1 # Versioning Library for Go
2 [![Build Status](https://travis-ci.org/hashicorp/go-version.svg?branch=master)](https://travis-ci.org/hashicorp/go-version)
4 go-version is a library for parsing versions and version constraints,
5 and verifying versions against a set of constraints. go-version
6 can sort a collection of versions properly, handles prerelease/beta
7 versions, can increment versions, etc.
9 Versions used with go-version must follow [SemVer](http://semver.org/).
11 ## Installation and Usage
13 Package documentation can be found on
14 [GoDoc](http://godoc.org/github.com/hashicorp/go-version).
16 Installation can be done with a normal `go get`:
19 $ go get github.com/hashicorp/go-version
22 #### Version Parsing and Comparison
25 v1, err := version.NewVersion("1.2")
26 v2, err := version.NewVersion("1.5+metadata")
28 // Comparison example. There is also GreaterThan, Equal, and just
29 // a simple Compare that returns an int allowing easy >=, <=, etc.
31 fmt.Printf("%s is less than %s", v1, v2)
35 #### Version Constraints
38 v1, err := version.NewVersion("1.2")
40 // Constraints example.
41 constraints, err := version.NewConstraint(">= 1.0, < 1.4")
42 if constraints.Check(v1) {
43 fmt.Printf("%s satisfies constraints %s", v1, constraints)
50 versionsRaw := []string{"1.1", "0.7.1", "1.4-beta", "1.4", "2"}
51 versions := make([]*version.Version, len(versionsRaw))
52 for i, raw := range versionsRaw {
53 v, _ := version.NewVersion(raw)
57 // After this, the versions are properly sorted
58 sort.Sort(version.Collection(versions))
61 ## Issues and Contributing
63 If you find an issue with this library, please report an issue. If you'd
64 like, we welcome any contributions. Fork this library and submit a pull