.github
update ci tools.gitignore
Update pipeline config and tools (#17).golangci.yml
Update pipeline config and tools (#17).revive.toml
Add linter tests (#7)constraint_test.go
Support period after version core (#2)constraint.go
Add linter tests (#7)go.mod
Update pipeline config and tools (#17)go.sum
Update pipeline config and tools (#17)LICENSE
LICENSEMakefile
fix linting pipeline (#19)README.md
Update Links in README (#9)version_collection_test.go
fix linting pipeline (#19)version_collection.go
fix linting pipeline (#19)version_test.go
Update version_test.go (#16)version.go
if prerelease is also compare make a simple string compare of metadata (#18)Versioning Library for Go
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.
Versions used with go-version must follow SemVer.
Installation and Usage
Package documentation can be found on GoDoc.
Installation can be done with a normal go get:
$ go get github.com/6543/go-versionVersion 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.
if v1.LessThan(v2) {
fmt.Printf("%s is less than %s", v1, v2)
}Version Constraints
v1, err := version.NewVersion("1.2")
// Constraints example.
constraints, err := version.NewConstraint(">= 1.0, < 1.4")
if constraints.Check(v1) {
fmt.Printf("%s satisfies constraints %s", v1, constraints)
}Version Sorting
versionsRaw := []string{"1.1", "0.7.1", "1.4-beta", "1.4", "2"}
versions := make([]*version.Version, len(versionsRaw))
for i, raw := range versionsRaw {
v, _ := version.NewVersion(raw)
versions[i] = v
}
// After this, the versions are properly sorted
sort.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.