Skip to content

Commit

Permalink
Add doc comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Sep 4, 2023
1 parent 6d66106 commit 74080dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (c *Collection) unmarshal(strSlice []string) error {
return nil
}

// UnmarshalText implements the json.Marshaler interface.
func (c *Collection) MarshalJSON() ([]byte, error) {
strSlice, err := c.marshal()
if err != nil {
Expand All @@ -66,6 +67,7 @@ func (c *Collection) MarshalJSON() ([]byte, error) {
return json.Marshal(strSlice)
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (c *Collection) UnmarshalJSON(data []byte) error {
var strSlice []string
if err := json.Unmarshal(data, &strSlice); err != nil {
Expand All @@ -74,10 +76,12 @@ func (c *Collection) UnmarshalJSON(data []byte) error {
return c.unmarshal(strSlice)
}

// MarshalYAML implements the yaml.Marshaler interface.
func (c *Collection) MarshalYAML() (interface{}, error) {
return c.marshal()
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *Collection) UnmarshalYAML(unmarshal func(interface{}) error) error {
var strSlice []string
if err := unmarshal(&strSlice); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ func (v *Version) Compare(b *Version) int {
return 1
}

// MarshalJSON implements the json.Marshaler interface.
func (v *Version) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", v.String())), nil
}

// MarshalYAML implements the yaml.Marshaler interface.
func (v *Version) MarshalYAML() (interface{}, error) {
return v.String(), nil
}
Expand All @@ -131,10 +133,12 @@ func (v *Version) unmarshal(f func(interface{}) error) error {
return nil
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (v *Version) UnmarshalYAML(f func(interface{}) error) error {
return v.unmarshal(f)
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (v *Version) UnmarshalJSON(b []byte) error {
s := strings.TrimSpace(strings.Trim(string(b), "\""))
return v.unmarshal(func(i interface{}) error {
Expand All @@ -143,7 +147,7 @@ func (v *Version) UnmarshalJSON(b []byte) error {
})
}

// NewVersion creates a new k0s version from a string
// NewVersion returns a new Version created from the supplied string or an error if the string is not a valid version number
func NewVersion(v string) (*Version, error) {
n, err := goversion.NewVersion(strings.TrimPrefix(v, "v"))
if err != nil {
Expand Down

0 comments on commit 74080dc

Please sign in to comment.