1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# go-rpm-version
[](https://travis-ci.org/knqyf263/go-rpm-version)
[](https://coveralls.io/github/knqyf263/go-rpm-version?branch=master)
[](https://goreportcard.com/report/github.com/knqyf263/go-rpm-version)
[](https://github.com/knqyf263/go-rpm-version/blob/master/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 and Usage
Installation can be done with a normal go get:
```
$ go get github.com/knqyf263/go-rpm-version
```
## Version Parsing and Comparison
```
import "github.com/knqyf263/go-rpm-version"
v1, err := version.NewVersion("2:6.0-1")
v2, err := 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)
}
```
## Version Sorting
```
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 {
v, _ := version.NewVersion(r)
vs[i] = v
}
sort.Slice(vs, func(i, j int) bool {
return vs[i].LessThan(vs[j])
})
```
# Contribute
1. fork a repository: github.com/knqyf263/go-rpm-version to github.com/you/repo
2. get original code: `go get github.com/knqyf263/go-rpm-version`
3. work on original code
4. add remote to your repo: git remote add myfork https://github.com/you/repo.git
5. push your changes: git push myfork
6. create a new Pull Request
- see [GitHub and Go: forking, pull requests, and go-getting](http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html)
----
# License
MIT
# Author
Teppei Fukuda
|