Documentation ¶
Overview ¶
Package version provides a version type and methods for working with versions.
Index ¶
- func CompareASC[T HasVersion](v, o T) int
- func CompareDESC[T HasVersion](v, o T) int
- type HasVersion
- type V
- func (v V) Compare(o V) int
- func (v V) Empty() bool
- func (v V) Equal(o V) bool
- func (v V) FormatString() string
- func (v V) GitVersion() string
- func (v V) Invalid() bool
- func (v V) LessThen(o V) bool
- func (v V) NextMajor() V
- func (v V) NextMinor() V
- func (v V) NextPatch() V
- func (V) Start() V
- func (v V) String() string
- func (v V) Version() V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareASC ¶
func CompareASC[T HasVersion](v, o T) int
CompareASC compares two versions (ASC) (less to greater). Use in slices.SortFunc.
Example usage:
slices.SortFunc(tags, version.CompareDESC[version.Version])
func CompareDESC ¶
func CompareDESC[T HasVersion](v, o T) int
CompareDESC compares two versions (DESC) (greater to less). Use in slices.SortFunc.
Example usage:
slices.SortFunc(tags, version.CompareDESC[version.Version])
Types ¶
type V ¶
type V string
V version. Example: 1.0.0-asd+dd
[SEMANTIC VERSIONING] https://semver.org/
func (V) Compare ¶
Compare with other version: @see https://semver.org/#spec-item-11
Precedence refers to how versions are compared to each other when ordered.
Precedence MUST be calculated by separating the version into major, minor, patch and pre-release identifiers in that order (Build metadata does not figure into precedence).
Precedence is determined by the first difference when comparing each of these identifiers from left to right as follows: Major, minor, and patch versions are always compared numerically.
Example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version:
Example: 1.0.0-alpha < 1.0.0.
Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows:
- Identifiers consisting of only digits are compared numerically.
- Identifiers with letters or hyphens are compared lexically in ASCII sort order. -Numeric identifiers always have lower precedence than non-numeric identifiers.
- A larger set of pre-release fields has a higher precedence than a smaller set, if all the preceding identifiers are equal.
Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
Return values are:
- 0: equal;
- 1: greater, then argument;
- -1: les, then argument
func (V) FormatString ¶
FormatString returns the string value of the version in the specified format.
func (V) GitVersion ¶
GitVersion returns the git version (version, started from "v").