A golang library for parsing rpm package versions
MIT License
A Go library for parsing rpm package versions
go-rpm-version is a library for parsing and comparing rpm versions
For the original C implementation, see: https://github.com/rpm-software-management/rpm/blob/master/lib/rpmvercmp.c#L16
OS: RedHat/CentOS
Installation can be done with a normal go get:
$ go get github.com/knqyf263/go-rpm-version
import version "github.com/knqyf263/go-rpm-version"
v1 := version.NewVersion("2:6.0-1")
v2 := version.NewVersion("2:6.0-2.el6")
// Comparison example. There is also GreaterThan, Equal.
if v1.LessThan(v2) {
fmt.Printf("%s is less than %s", v1, v2)
}
raw := []string{"5.3p1-112", "3.6.1p2-21.sel", "3.6.1p2-22", "5.3p1-105", "3.6.1p2-21"}
vs := make([]version.Version, len(raw))
for i, r := range raw {
vs[i] = version.NewVersion(r)
}
sort.Slice(vs, func(i, j int) bool {
return vs[i].LessThan(vs[j])
})
go get github.com/knqyf263/go-rpm-version
MIT
Teppei Fukuda