modulepackage
0.0.0-20190830083331-035f6764e8d2
Repository: https://github.com/mcuadros/go-version.git
Documentation: pkg.go.dev
# README
go-version

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
# Functions
Compare compares two version number strings, for a particular relationship
Usage version.Compare("2.3.4", "v3.1.2", "<") Returns: true
version.Compare("1.0rc1", "1.0", ">=") Returns: false.
CompareNormalized compares two normalizated version number strings, for a particular relationship
The function first replaces _, - and + with a dot .
CompareSimple compares two normalizated version number strings
Just the same of CompareVersion but return a int result, 0 if both version are equal, 1 if the right side is bigger and -1 if the right side is lower
Usage version.CompareSimple("1.2", "1.0.1") Returns: 1
version.CompareSimple("1.0rc1", "1.0") Returns: -1.
No description provided by the author
NewConstrain returns a new Constrain and sets operator and version to compare.
NewConstrainGroup returns a new NewConstrainGroup.
NewConstrainGroupFromString returns a new NewConstrainGroup and create the constraints based on a string
Version constraints can be specified in a few different ways:
Exact version: You can specify the exact version of a package, for example 1.0.2.
Normalizes a version string to be able to perform comparisons on it
Example: version.Normalize("10.4.13-b") Returns: 10.4.13.0-beta
.
No description provided by the author
No description provided by the author
Sorts a string slice of version number strings using version.CompareSimple()
Example: 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"}
.
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
PCRegMap : PreCompiled Regex Map.