Documentation ¶
Index ¶
- Variables
- func FinalizeVersion(s string) (string, error)
- func NewBuildVersion(s string) (string, error)
- func Sort(versions []Version)
- type PRVersion
- type Range
- type Version
- func (v Version) Compare(o Version) int
- func (v Version) EQ(o Version) bool
- func (v Version) Equals(o Version) bool
- func (v Version) FinalizeVersion() string
- func (v Version) GE(o Version) bool
- func (v Version) GT(o Version) bool
- func (v Version) GTE(o Version) bool
- func (v *Version) IncrementMajor() error
- func (v *Version) IncrementMinor() error
- func (v *Version) IncrementPatch() error
- func (v Version) LE(o Version) bool
- func (v Version) LT(o Version) bool
- func (v Version) LTE(o Version) bool
- func (v Version) MarshalJSON() ([]byte, error)
- func (v Version) NE(o Version) bool
- func (v *Version) Scan(src interface{}) (err error)
- func (v Version) String() string
- func (v *Version) UnmarshalJSON(data []byte) (err error)
- func (v Version) Validate() error
- func (v Version) Value() (driver.Value, error)
- type Versions
Constants ¶
This section is empty.
Variables ¶
var SpecVersion = Version{
Major: 2,
Minor: 0,
Patch: 0,
}
SpecVersion is the latest fully supported spec version of semver
Functions ¶
func FinalizeVersion ¶
FinalizeVersion returns the major, minor and patch number only and discards prerelease and build number.
func NewBuildVersion ¶
NewBuildVersion creates a new valid build version
Types ¶
type PRVersion ¶
PRVersion represents a PreRelease Version
func NewPRVersion ¶
NewPRVersion creates a new valid prerelease version
func (PRVersion) Compare ¶
Compare compares two PreRelease Versions v and o: -1 == v is less than o 0 == v is equal to o 1 == v is greater than o
type Range ¶
Range represents a range of versions. A Range can be used to check if a Version satisfies it:
range, err := semver.ParseRange(">1.0.0 <2.0.0") range(semver.MustParse("1.1.1") // returns true
func MustParseRange ¶
MustParseRange is like ParseRange but panics if the range cannot be parsed.
func ParseRange ¶
ParseRange parses a range and returns a Range. If the range could not be parsed an error is returned.
Valid ranges are:
- "<1.0.0"
- "<=1.0.0"
- ">1.0.0"
- ">=1.0.0"
- "1.0.0", "=1.0.0", "==1.0.0"
- "!1.0.0", "!=1.0.0"
A Range can consist of multiple ranges separated by space: Ranges can be linked by logical AND:
- ">1.0.0 <2.0.0" would match between both ranges, so "1.1.1" and "1.8.7" but not "1.0.0" or "2.0.0"
- ">1.0.0 <3.0.0 !2.0.3-beta.2" would match every version between 1.0.0 and 3.0.0 except 2.0.3-beta.2
Ranges can also be linked by logical OR:
- "<2.0.0 || >=3.0.0" would match "1.x.x" and "3.x.x" but not "2.x.x"
AND has a higher precedence than OR. It's not possible to use brackets.
Ranges can be combined by both AND and OR
- `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1`
type Version ¶
type Version struct { Major uint64 Minor uint64 Patch uint64 Pre []PRVersion Build []string //No Precedence }
Version represents a semver compatible version
func Make ¶
Make is an alias for Parse, parses version string and returns a validated Version or error
func New ¶
New is an alias for Parse and returns a pointer, parses version string and returns a validated Version or error
func ParseTolerant ¶
ParseTolerant allows for certain version specifications that do not strictly adhere to semver specs to be parsed by this library. It does so by normalizing versions before passing them to Parse(). It currently trims spaces, removes a "v" prefix, adds a 0 patch number to versions with only major and minor components specified, and removes leading 0s.
func (Version) Compare ¶
Compare compares Versions v to o: -1 == v is less than o 0 == v is equal to o 1 == v is greater than o
func (Version) FinalizeVersion ¶
FinalizeVersion discards prerelease and build number and only returns major, minor and patch number.
func (*Version) IncrementMajor ¶
IncrementMajor increments the major version
func (*Version) IncrementMinor ¶
IncrementMinor increments the minor version
func (*Version) IncrementPatch ¶
IncrementPatch increments the patch version
func (Version) MarshalJSON ¶
MarshalJSON implements the encoding/json.Marshaler interface.
func (*Version) UnmarshalJSON ¶
UnmarshalJSON implements the encoding/json.Unmarshaler interface.