Debian Codegraph @

README.md

raw
1 # go-rpm-version
2
3 [![Build Status](https://travis-ci.org/knqyf263/go-rpm-version.svg?branch=master)](https://travis-ci.org/knqyf263/go-rpm-version)
4 [![Coverage Status](https://coveralls.io/repos/github/knqyf263/go-rpm-version/badge.svg?branch=master)](https://coveralls.io/github/knqyf263/go-rpm-version?branch=master)
5 [![Go Report Card](https://goreportcard.com/badge/github.com/knqyf263/go-rpm-version)](https://goreportcard.com/report/github.com/knqyf263/go-rpm-version)
6 [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/knqyf263/go-rpm-version/blob/master/LICENSE)
7
8 A Go library for parsing rpm package versions
9
10 go-rpm-version is a library for parsing and comparing rpm versions
11
12 For the original C implementation, see:
13 https://github.com/rpm-software-management/rpm/blob/master/lib/rpmvercmp.c#L16
14
15 OS: RedHat/CentOS
16
17 # Installation and Usage
18
19 Installation can be done with a normal go get:
20
21 ```
22 $ go get github.com/knqyf263/go-rpm-version
23 ```
24
25 ## Version Parsing and Comparison
26
27 ```
28 import version "github.com/knqyf263/go-rpm-version"
29
30 v1 := version.NewVersion("2:6.0-1")
31 v2 := version.NewVersion("2:6.0-2.el6")
32
33 // Comparison example. There is also GreaterThan, Equal.
34 if v1.LessThan(v2) {
35 fmt.Printf("%s is less than %s", v1, v2)
36 }
37 ```
38
39 ## Version Sorting
40
41 ```
42 raw := []string{"5.3p1-112", "3.6.1p2-21.sel", "3.6.1p2-22", "5.3p1-105", "3.6.1p2-21"}
43 vs := make([]version.Version, len(raw))
44 for i, r := range raw {
45 vs[i] = version.NewVersion(r)
46 }
47
48 sort.Slice(vs, func(i, j int) bool {
49 return vs[i].LessThan(vs[j])
50 })
51 ```
52
53 # Contribute
54
55 1. fork a repository: github.com/knqyf263/go-rpm-version to github.com/you/repo
56 2. get original code: `go get github.com/knqyf263/go-rpm-version`
57 3. work on original code
58 4. add remote to your repo: git remote add myfork https://github.com/you/repo.git
59 5. push your changes: git push myfork
60 6. create a new Pull Request
61
62 - see [GitHub and Go: forking, pull requests, and go-getting](http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html)
63
64 ----
65
66 # License
67 MIT
68
69 # Author
70 Teppei Fukuda