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) 3 4go-version is a library for parsing versions and version constraints, 5and verifying versions against a set of constraints. go-version 6can sort a collection of versions properly, handles prerelease/beta 7versions, can increment versions, etc. 8 9Versions used with go-version must follow [SemVer](http://semver.org/). 10 11## Installation and Usage 12 13Package documentation can be found on 14[GoDoc](http://godoc.org/github.com/hashicorp/go-version). 15 16Installation can be done with a normal `go get`: 17 18``` 19$ go get github.com/hashicorp/go-version 20``` 21 22#### Version Parsing and Comparison 23 24```go 25v1, err := version.NewVersion("1.2") 26v2, err := version.NewVersion("1.5+metadata") 27 28// Comparison example. There is also GreaterThan, Equal, and just 29// a simple Compare that returns an int allowing easy >=, <=, etc. 30if v1.LessThan(v2) { 31 fmt.Printf("%s is less than %s", v1, v2) 32} 33``` 34 35#### Version Constraints 36 37```go 38v1, err := version.NewVersion("1.2") 39 40// Constraints example. 41constraints, err := version.NewConstraint(">= 1.0, < 1.4") 42if constraints.Check(v1) { 43 fmt.Printf("%s satisfies constraints %s", v1, constraints) 44} 45``` 46 47#### Version Sorting 48 49```go 50versionsRaw := []string{"1.1", "0.7.1", "1.4-beta", "1.4", "2"} 51versions := make([]*version.Version, len(versionsRaw)) 52for i, raw := range versionsRaw { 53 v, _ := version.NewVersion(raw) 54 versions[i] = v 55} 56 57// After this, the versions are properly sorted 58sort.Sort(version.Collection(versions)) 59``` 60 61## Issues and Contributing 62 63If you find an issue with this library, please report an issue. If you'd 64like, we welcome any contributions. Fork this library and submit a pull 65request. 66