You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
go-version is a library for parsing versions and version constraints,
and verifying versions against a set of constraints. go-version
can sort a collection of versions properly, handles prerelease/beta
versions, can increment versions, etc.
Package documentation can be found on
Go Reference.
Installation can be done with a normal go get:
$ go get github.com/hashicorp/go-version
Version Parsing and Comparison
v1, err:=version.NewVersion("1.2")
v2, err:=version.NewVersion("1.5+metadata")
// Comparison example. There is also GreaterThan, Equal, and just// a simple Compare that returns an int allowing easy >=, <=, etc.ifv1.LessThan(v2) {
fmt.Printf("%s is less than %s", v1, v2)
}
versionsRaw:= []string{"1.1", "0.7.1", "1.4-beta", "1.4", "2"}
versions:=make([]*version.Version, len(versionsRaw))
fori, raw:=rangeversionsRaw {
v, _:=version.NewVersion(raw)
versions[i] =v
}
// After this, the versions are properly sortedsort.Sort(version.Collection(versions))
Issues and Contributing
If you find an issue with this library, please report an issue. If you'd
like, we welcome any contributions. Fork this library and submit a pull
request.
About
A Go (golang) library for parsing and verifying versions and version constraints.