Golang: go-version library for parsing and comparing versions

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 main
import (
    "fmt"
    "github.com/hashicorp/go-version"
)
func main() {
    v1, _ := version.NewVersion("1.2")
    v2, _ := version.NewVersion("2.1")
    if v1.LessThan(v2) {
        fmt.Printf("%s is less than %s", v1, v2)
    }
    // 1.2.0 is less than 2.1.0
}

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish