Documentation
¶
Overview ¶
Package vc compare version strings to find greater, equal or lesser. Provides the ability to work with Semantic Versions (http://semver.org) in Go.
Index ¶
- Constants
- Variables
- func Compare(v1, v2 Comparable) int
- func Eq(v1, v2 Comparable) bool
- func Gt(v1, v2 Comparable) bool
- func Lt(v1, v2 Comparable) bool
- type CalVer
- func (v *CalVer) Compare(o *CalVer) int
- func (v *CalVer) Eq(o *CalVer) bool
- func (v *CalVer) Gt(o *CalVer) bool
- func (v *CalVer) IncMajor() Comparable
- func (v *CalVer) IncMinor() Comparable
- func (v *CalVer) IncPatch() Comparable
- func (v *CalVer) Lt(o *CalVer) bool
- func (v *CalVer) Major() uint64
- func (v *CalVer) Metadata() string
- func (v *CalVer) Minor() uint64
- func (v *CalVer) Original() string
- func (v *CalVer) Patch() uint64
- func (v *CalVer) Prerelease() string
- func (v *CalVer) String() string
- func (v *CalVer) Version() string
- type Comparable
- type Constraints
- type New
- type Semver
- func (v *Semver) Compare(o *Semver) int
- func (v *Semver) Eq(o *Semver) bool
- func (v *Semver) Gt(o *Semver) bool
- func (v *Semver) IncMajor() Comparable
- func (v *Semver) IncMinor() Comparable
- func (v *Semver) IncPatch() Comparable
- func (v *Semver) Lt(o *Semver) bool
- func (v *Semver) Major() uint64
- func (v *Semver) Metadata() string
- func (v *Semver) Minor() uint64
- func (v *Semver) Original() string
- func (v *Semver) Patch() uint64
- func (v *Semver) Prerelease() string
- func (v *Semver) String() string
- func (v *Semver) Version() string
Constants ¶
const ( OperatorGte = ">=" OperatorGt = ">" OperatorLte = "<=" OperatorLt = "<" OperatorEq = "=" OperatorRange = " - " OperatorCaret = "^" OperatorTilde = "~" )
const ( VersionAll = "*" VersionX = "x" VersionMinimum = "0.0.0" VersionAllAlias = OperatorGte + VersionMinimum )
Variables ¶
var ( // ErrInvalidSemVer is returned a version is found to be invalid when // being parsed. ErrInvalidSemVer = errors.New("invalid semantic version") // ErrInvalidCalVer is returned a version is found to be invalid when // being parsed. ErrInvalidCalVer = errors.New("invalid calendar version") // ErrInvalidConstraint is returned a constraint is found to be invalid when // being parsed. ErrInvalidConstraint = errors.New("invalid constraint") // ErrSegmentStartsZero is returned when a version segment starts with 0. // This is invalid in SemVer. ErrSegmentStartsZero = errors.New("version segment starts with 0") // ErrInvalidMetadata is returned when the metadata is an invalid format ErrInvalidMetadata = errors.New("invalid metadata string") // ErrInvalidPrerelease is returned when the pre-release is an invalid format ErrInvalidPrerelease = errors.New("invalid prerelease string") )
Functions ¶
func Compare ¶
func Compare(v1, v2 Comparable) int
Compare compares a Comparable to another one. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other version.
Prerelease is lower than the version without a prerelease. Compare always takes into account prerelease. If you want to work with ranges using typical range syntax that skip prerelease if the range is not looking for them use constraints.
func Eq ¶
func Eq(v1, v2 Comparable) bool
Eq tests if two versions are equal to each other. Note, versions can be equal with different metadata since metadata is not considered part of the comparable version.
Types ¶
type CalVer ¶
type CalVer struct {
// contains filtered or unexported fields
}
func NewCalVer ¶
NewCalVer creates a new instance of CalVer with each of the parts passed in as arguments instead of parsing a version string.
func NewCalVerStr ¶
NewCalVerStr parses a given version and returns an instance of CalVer or an error if unable to parse the version. If the version is SemVer-ish it attempts to convert it to CalVer.
func (*CalVer) Compare ¶
Compare compares this version to another CalVer. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other version.
func (*CalVer) IncMajor ¶
func (v *CalVer) IncMajor() Comparable
IncMajor produces the next major version. Sets patch to 0. Sets minor to 0. Increments major number. Unsets prerelease status.
func (*CalVer) IncMinor ¶
func (v *CalVer) IncMinor() Comparable
IncMinor produces the next minor version. Sets patch to 0. Increments minor number. Unsets prerelease status.
func (*CalVer) IncPatch ¶
func (v *CalVer) IncPatch() Comparable
IncPatch produces the next patch version. If the current version does not have prerelease information, it unsets prerelease values, increments patch number. If the current version has any of prerelease information, it unsets both values and keeps current patch value
func (*CalVer) Prerelease ¶
Prerelease returns the prerelease version.
func (*CalVer) String ¶
String converts a CalVer object to a string. Note, if the original version contained a leading v this version will not. See the Original() method to retrieve the original value. Semantic Versions don't contain a leading v per the spec. Instead, it's optional on implementation.
type Comparable ¶
type Comparable interface { // Version converts major,minor and patch to a string. Version() string // Major returns the major version. Major() uint64 // Minor returns the minor version. Minor() uint64 // Patch returns the patch version. Patch() uint64 // Prerelease returns the prerelease version. Prerelease() string // IncMajor produces the next major version. IncMajor() Comparable // IncMinor produces the next minor version. IncMinor() Comparable // IncPatch produces the next patch version. IncPatch() Comparable }
Comparable An implementation of Comparable interface can be compared with constraints.
type Constraints ¶
type Constraints struct {
// contains filtered or unexported fields
}
Constraints is one or more constraint that a version can be checked against.
func NewConstraint ¶
func NewConstraint(c string, fn New) (*Constraints, error)
NewConstraint returns a Constraints instance that a Comparable instance can be checked against. If there is a parse error it will be returned.
func (*Constraints) Check ¶
func (c *Constraints) Check(ver Comparable) bool
func (*Constraints) CheckString ¶
func (c *Constraints) CheckString(ver string) (bool, error)
type New ¶
type New func(string) (Comparable, error)
New a function to generate a Comparable instance.
type Semver ¶
type Semver struct {
// contains filtered or unexported fields
}
func NewSemver ¶
NewSemver creates a new instance of Semver with each of the parts passed in as arguments instead of parsing a version string.
func NewSemverStr ¶
NewSemverStr parses a given version and returns an instance of Semver or an error if unable to parse the version. If the version is SemVer-ish it attempts to convert it to Semver.
func (*Semver) Compare ¶
Compare compares this version to another Semver. It returns -1, 0, or 1 if the version smaller, equal, or larger than the other version.
Versions are compared by X.Y.Z. Build metadata is ignored. Prerelease is lower than the version without a prerelease. Compare always takes into account prereleases. If you want to work with ranges using typical range syntaxes that skip prereleases if the range is not looking for them use constraints.
func (*Semver) Eq ¶
Eq tests if two versions are equal to each other. Note, versions can be equal with different metadata since metadata is not considered part of the comparable version.
func (*Semver) IncMajor ¶
func (v *Semver) IncMajor() Comparable
IncMajor produces the next major version. Sets patch to 0. Sets minor to 0. Increments major number. Unsets metadata. Unsets prerelease status.
func (*Semver) IncMinor ¶
func (v *Semver) IncMinor() Comparable
IncMinor produces the next minor version. Sets patch to 0. Increments minor number. Unsets metadata. Unsets prerelease status.
func (*Semver) IncPatch ¶
func (v *Semver) IncPatch() Comparable
IncPatch produces the next patch version. If the current version does not have prerelease/metadata information, it unsets metadata and prerelease values, increments patch number. If the current version has any of prerelease or metadata information, it unsets both values and keeps current patch value
func (*Semver) Prerelease ¶
Prerelease returns the prerelease version.
func (*Semver) String ¶
String converts a Semver object to a string. Note, if the original version contained a leading v this version will not. See the Original() method to retrieve the original value. Semantic Versions don't contain a leading v per the spec. Instead, it's optional on implementation.