Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ascending ¶
type Ascending []Version
Sorts versions Ascending via the sorts standard lib package. resulting order: 1.0.0, 1.1.0, 2.0.0.
Example ¶
package main import ( "fmt" "sort" "pkg.package-operator.run/semver" ) func main() { versions := []semver.Version{ semver.MustNewVersion("1.2.4"), semver.MustNewVersion("1.2.3"), semver.MustNewVersion("1.0.0"), semver.MustNewVersion("1.3.0"), semver.MustNewVersion("2.0.0"), semver.MustNewVersion("0.4.2"), } sort.Sort(semver.Ascending(versions)) fmt.Println(semver.VersionList(versions).String()) }
Output: 0.4.2, 1.0.0, 1.2.3, 1.2.4, 1.3.0, 2.0.0
type Constraint ¶
type Constraint interface { // Check if the version is allowed by the constraint or not. Check(v Version) bool // Check if a range is contained within a constraint. Contains(or Constraint) bool // Returns the string representation of this constraint. String() string }
Constraint interface is common to all version constraints.
func MustNewConstraint ¶
func MustNewConstraint(data string) Constraint
Parses the given string into a Version Constraint or panics.
func NewConstraint ¶
func NewConstraint(data string) (Constraint, error)
Parses the given string into a Version Constraint.
Example (Range) ¶
package main import ( "fmt" "pkg.package-operator.run/semver" ) func main() { constraint := "1.0.0 - 2.0.0" c, err := semver.NewConstraint(constraint) if err != nil { panic(err) } notContained := semver.MustNewConstraint("2.0.0 - 3.0.0") contained := semver.MustNewConstraint("1.0.0 - 1.4.0") fmt.Printf("1.0.0 - 1.4.0 is contained in range %q: %v\n", constraint, c.Contains(contained)) fmt.Printf("2.0.0 - 3.0.0 is contained in range %q: %v\n", constraint, c.Contains(notContained)) }
Output: 1.0.0 - 1.4.0 is contained in range "1.0.0 - 2.0.0": true 2.0.0 - 3.0.0 is contained in range "1.0.0 - 2.0.0": false
Example (Version) ¶
package main import ( "fmt" "pkg.package-operator.run/semver" ) func main() { constraint := "1.0.0 - 2.0.0" c, err := semver.NewConstraint(constraint) if err != nil { panic(err) } notContained := semver.MustNewVersion("3.0.0") contained := semver.MustNewVersion("1.2.0") fmt.Printf("%s is contained in range %q: %v\n", contained.String(), constraint, c.Check(contained)) fmt.Printf("%s is contained in range %q: %v\n", notContained.String(), constraint, c.Check(notContained)) }
Output: 1.2.0 is contained in range "1.0.0 - 2.0.0": true 3.0.0 is contained in range "1.0.0 - 2.0.0": false
type Descending ¶
type Descending []Version
Sorts versions Descending via the sorts standard lib package. resulting order: 2.0.0, 1.1.0, 1.0.0.
Example ¶
package main import ( "fmt" "sort" "pkg.package-operator.run/semver" ) func main() { versions := []semver.Version{ semver.MustNewVersion("1.2.4"), semver.MustNewVersion("1.2.3"), semver.MustNewVersion("1.0.0"), semver.MustNewVersion("1.3.0"), semver.MustNewVersion("2.0.0"), semver.MustNewVersion("0.4.2"), } sort.Sort(semver.Descending(versions)) fmt.Println(semver.VersionList(versions).String()) }
Output: 2.0.0, 1.3.0, 1.2.4, 1.2.3, 1.0.0, 0.4.2
func (Descending) Len ¶
func (l Descending) Len() int
Returns the number of items of the slice. Implements sort.Interface.
func (Descending) Less ¶
func (l Descending) Less(i, j int) bool
Returns true if item[j] is less than item[i]. Implements sort.Interface.
func (Descending) Swap ¶
func (l Descending) Swap(i, j int)
Swaps the position of two items in the list. Implements sort.Interface.
type PreReleaseIdentifier ¶
type PreReleaseIdentifier struct {
// contains filtered or unexported fields
}
PreReleaseIdentifier can be alphanumeric or a number.
func ToPreReleaseIdentifier ¶
func ToPreReleaseIdentifier(s string) PreReleaseIdentifier
Converts the given string into a PreReleaseIdentifier.
func (*PreReleaseIdentifier) Compare ¶
func (s *PreReleaseIdentifier) Compare(o PreReleaseIdentifier) int
Compare compares this pre release identifier to another one. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other identifier.
func (*PreReleaseIdentifier) GetNumber ¶
func (s *PreReleaseIdentifier) GetNumber() (uint64, bool)
func (*PreReleaseIdentifier) GetString ¶
func (s *PreReleaseIdentifier) GetString() (string, bool)
func (*PreReleaseIdentifier) Interface ¶
func (s *PreReleaseIdentifier) Interface() interface{}
func (*PreReleaseIdentifier) String ¶
func (s *PreReleaseIdentifier) String() string
type PreReleaseIdentifierList ¶
type PreReleaseIdentifierList []PreReleaseIdentifier
func (PreReleaseIdentifierList) Compare ¶
func (l PreReleaseIdentifierList) Compare(o []PreReleaseIdentifier) int
Compare compares this pre release identifier list to another one. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other list.
func (PreReleaseIdentifierList) String ¶
func (l PreReleaseIdentifierList) String() string
type Range ¶
Range represents a min to max version range. Min and Max are inclusive >=/<= e.g. 1.0.0 - 1.1.0 would contain both 1.0.0 and 1.1.0.
func (*Range) Contains ¶
func (r *Range) Contains(other Constraint) bool
Checks if the given constraint fits into this range.
type Version ¶
type Version struct {
Major, Minor, Patch uint64
PreRelease PreReleaseIdentifierList
BuildMetadata []string
}
Represents a Semantic Versioning 2.0.0 Version.
func MustNewVersion ¶
Parses the given string into a Version object and panics on error.
Example ¶
package main import ( "fmt" "pkg.package-operator.run/semver" ) func main() { v := semver.MustNewVersion("1.2.4-alpha.0+meta") fmt.Println(v.Major, v.Minor, v.Patch, v.PreRelease, v.BuildMetadata) }
Output: 1 2 4 alpha.0 [meta]
func NewVersion ¶
Parses the given string into a Version object.
Example ¶
package main import ( "fmt" "pkg.package-operator.run/semver" ) func main() { v, err := semver.NewVersion("1.2.4-alpha.0+meta") if err != nil { panic(err) } fmt.Println(v.Major, v.Minor, v.Patch, v.PreRelease, v.BuildMetadata) }
Output: 1 2 4 alpha.0 [meta]
func (*Version) Compare ¶
Compare compares this version to another one. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other version.
func (*Version) GreaterThan ¶
GreaterThan tests if one version is greater than another one.
type VersionList ¶
type VersionList []Version
VersionList keeps a list of versions and provides helper functions on them.
func (VersionList) String ¶
func (l VersionList) String() string
Prints the VersionList as comma and space ", " separated list.
func (VersionList) StringList ¶
func (l VersionList) StringList() []string
Converts all Versions into strings and returns them.