Documentation ¶
Overview ¶
Version normalizer and comparison library for go, heavy based on PHP version_compare function and Version comparsion libs from Composer (https://github.com/composer/composer) PHP project
Index ¶
- Constants
- func Compare(version1, version2, operator string) bool
- func CompareNormalized(version1, version2, operator string) bool
- func CompareSimple(version1, version2 string) int
- func GetStability(version string) int
- func Normalize(version string) string
- func RegFind(pattern, subject string) []string
- func RegSplit(pattern, subject string) []string
- func Sort(versionStrings []string)
- type Constraint
- type ConstraintGroup
Constants ¶
const ( Development = iota Alpha Beta RC Stable )
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compares two version number strings, for a particular relationship
Usage
version.Compare("2.3.4", "v3.1.2", "<") Returns: true version.Compare("1.0rc1", "1.0", ">=") Returns: false
func CompareNormalized ¶
Compares two normalizated version number strings, for a particular relationship
The function first replaces _, - and + with a dot . in the version strings and also inserts dots . before and after any non number so that for example '4.3.2RC1' becomes '4.3.2.RC.1'.
Then it splits the results like if you were using Split(version, '.'). Then it compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: any string not found in this list:
< dev < alpha = a < beta = b < RC = rc < # < pl = p.
Usage
version.CompareNormalized("1.0-dev", "1.0", "<") Returns: true version.CompareNormalized("1.0rc1", "1.0", ">=") Returns: false version.CompareNormalized("1.0", "1.0b1", "ge") Returns: true
func CompareSimple ¶
Compares two normalizated version number strings
Just the same of CompareVersion but return a int result, 0 if both version are equal, 1 if the right side is bigger and -1 if the right side is lower
Usage
version.CompareSimple("1.2", "1.0.1") Returns: 1 version.CompareSimple("1.0rc1", "1.0") Returns: -1
func GetStability ¶
Types ¶
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
func NewConstrain ¶
func NewConstrain(operator, version string) *Constraint
Return a new Constrain and sets operator and version to compare
func (*Constraint) GetOperator ¶
func (self *Constraint) GetOperator() string
Get operator to compare
func (*Constraint) Match ¶
func (self *Constraint) Match(version string) bool
Match a given version againts the constraint
func (*Constraint) SetOperator ¶
func (self *Constraint) SetOperator(operator string)
Sets operator to compare
func (*Constraint) SetVersion ¶
func (self *Constraint) SetVersion(version string)
Sets version to compare
type ConstraintGroup ¶
type ConstraintGroup struct {
// contains filtered or unexported fields
}
func NewConstrainGroupFromString ¶
func NewConstrainGroupFromString(name string) *ConstraintGroup
Return a new NewConstrainGroup and create the constraints based on a string
Version constraints can be specified in a few different ways:
Exact version: You can specify the exact version of a package, for example 1.0.2.
Range: By using comparison operators you can specify ranges of valid versions. Valid operators are >, >=, <, <=, !=. An example range would be >=1.0. You can define multiple ranges, separated by a comma: >=1.0,<2.0.
Wildcard: You can specify a pattern with a * wildcard. 1.0.* is the equivalent of >=1.0,<1.1.
Next Significant Release (Tilde Operator): The ~ operator is best explained by example: ~1.2 is equivalent to >=1.2,<2.0, while ~1.2.3 is equivalent to >=1.2.3,<1.3. As you can see it is mostly useful for projects respecting semantic versioning. A common usage would be to mark the minimum minor version you depend on, like ~1.2 (which allows anything up to, but not including, 2.0). Since in theory there should be no backwards compatibility breaks until 2.0, that works well. Another way of looking at it is that using ~ specifies a minimum version, but allows the last digit specified to go up.
By default only stable releases are taken into consideration. If you would like to also get RC, beta, alpha or dev versions of your dependencies you can do so using stability flags. To change that for all packages instead of doing per dependency you can also use the minimum-stability setting.
From: http://getcomposer.org/doc/01-basic-usage.md#package-versions
func (*ConstraintGroup) AddConstraint ¶
func (self *ConstraintGroup) AddConstraint(constraint ...*Constraint)
Adds a Contraint to the group
func (*ConstraintGroup) GetConstraints ¶
func (self *ConstraintGroup) GetConstraints() []*Constraint
Return all the constraints
func (*ConstraintGroup) Match ¶
func (self *ConstraintGroup) Match(version string) bool
Match a given version againts the group
Usage
c := version.NewConstrainGroupFromString(">2.0,<=3.0") c.Match("2.5.0beta") Returns: true c := version.NewConstrainGroupFromString("~1.2.3") c.Match("1.2.3.5") Returns: true