github.com/YousefHaggyHeroku/pack@v1.5.5/internal/builder/version.go (about) 1 package builder 2 3 import ( 4 "github.com/Masterminds/semver" 5 "github.com/pkg/errors" 6 ) 7 8 // Version is an extension to semver.Version to make it marshalable. 9 type Version struct { 10 semver.Version 11 } 12 13 // VersionMustParse parses a string into a Version 14 func VersionMustParse(v string) *Version { 15 return &Version{Version: *semver.MustParse(v)} 16 } 17 18 // String returns the string value of the Version 19 func (v *Version) String() string { 20 return v.Version.String() 21 } 22 23 // Equal compares two Versions 24 func (v *Version) Equal(other *Version) bool { 25 if other != nil { 26 return v.Version.Equal(&other.Version) 27 } 28 29 return false 30 } 31 32 // MarshalText makes Version satisfy the encoding.TextMarshaler interface. 33 func (v *Version) MarshalText() ([]byte, error) { 34 return []byte(v.Version.Original()), nil 35 } 36 37 // UnmarshalText makes Version satisfy the encoding.TextUnmarshaler interface. 38 func (v *Version) UnmarshalText(text []byte) error { 39 s := string(text) 40 w, err := semver.NewVersion(s) 41 if err != nil { 42 return errors.Wrapf(err, "invalid semantic version %s", s) 43 } 44 45 v.Version = *w 46 return nil 47 }