1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00
gitea/vendor/github.com/mcuadros/go-version
2019-05-01 11:44:16 -04:00
..
.gitignore Use Go1.11 module (#5743) 2019-03-27 19:15:23 +08:00
.travis.yml Use Go1.11 module (#5743) 2019-03-27 19:15:23 +08:00
compare.go update github.com/mcuadros/go-version to v0.0.0-20190308113854-92cdf37c5b75 (#6815) 2019-05-01 11:44:16 -04:00
constraint.go
doc.go Added all required dependencies 2016-11-04 08:43:11 +01:00
group.go update github.com/mcuadros/go-version to v0.0.0-20190308113854-92cdf37c5b75 (#6815) 2019-05-01 11:44:16 -04:00
LICENSE
normalize.go
README.md Use Go1.11 module (#5743) 2019-03-27 19:15:23 +08:00
sort.go
stability.go

go-version Build Status GoDoc

Version normalizer and comparison library for go, heavy based on PHP version_compare function and Version comparsion libs from Composer PHP project

Installation

The recommended way to install go-version

go get github.com/mcuadros/go-version

Examples

How import the package

import (
    "github.com/mcuadros/go-version"
)

version.Normalize(): Normalizes a version string to be able to perform comparisons on it

version.Normalize("10.4.13-b")
//Returns: 10.4.13.0-beta

version.CompareSimple(): Compares two normalizated version number strings

version.CompareSimple("1.2", "1.0.1")
//Returns: 1

version.CompareSimple("1.0rc1", "1.0")
//Returns: -1

version.Compare(): Compares two normalizated version number strings, for a particular relationship

version.Compare("1.0-dev", "1.0", "<")
//Returns: true

version.Compare("1.0rc1", "1.0", ">=")
//Returns: false

version.Compare("2.3.4", "v3.1.2", "<")
//Returns: true

version.ConstrainGroup.Match(): Match a given version againts a group of constrains, read about constraint string format at Composer documentation

c := version.NewConstrainGroupFromString(">2.0,<=3.0")
c.Match("2.5.0beta")
//Returns: true

c := version.NewConstrainGroupFromString("~1.2.3")
c.Match("1.2.3.5")
//Returns: true

version.Sort(): Sorts a string slice of version number strings using version.CompareSimple()

version.Sort([]string{"1.10-dev", "1.0rc1", "1.0", "1.0-dev"})
//Returns []string{"1.0-dev", "1.0rc1", "1.0", "1.10-dev"}

License

MIT, see LICENSE