-
Notifications
You must be signed in to change notification settings - Fork 2
/
yaml.go
55 lines (47 loc) · 1.23 KB
/
yaml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Copyright 2018-2023 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package semver
import (
"gopkg.in/yaml.v3"
)
// MarshalYAML implements yaml.Marshaler
func (v *Version) MarshalYAML() (interface{}, error) {
return v.String(), nil
}
// UnmarshalYAML implements yaml.Unmarshaler
func (v *Version) UnmarshalYAML(node *yaml.Node) error {
var versionString string
if err := node.Decode(&versionString); err != nil {
return err
}
parsed, err := Parse(versionString)
if err != nil {
return err
}
v.raw = parsed.raw
v.bytes = []byte(v.raw)
v.major = parsed.major
v.minor = parsed.minor
v.patch = parsed.patch
v.prerelease = parsed.prerelease
v.build = parsed.build
return nil
}
// MarshalYAML implements yaml.Marshaler
func (v *RelaxedVersion) MarshalYAML() (interface{}, error) {
return v.String(), nil
}
// UnmarshalYAML implements yaml.Unmarshaler
func (v *RelaxedVersion) UnmarshalYAML(node *yaml.Node) error {
var versionString string
if err := node.Decode(&versionString); err != nil {
return err
}
parsed := ParseRelaxed(versionString)
v.customversion = parsed.customversion
v.version = parsed.version
return nil
}