Documentation
¶
Overview ¶
Package version compares version-like strings that may or may not obey semantic-versioning rules.
It is built for the messy, real-world version identifiers returned by cloud APIs (for example, AWS RDS database engine versions) where strict semantic versioning parsers either error out or produce surprising results. Comparison never returns an error: when a value cannot be parsed as a semantic version, the package falls back to progressively looser strategies so that any two strings can always be ordered.
Precedence of comparison, highest to lowest:
- Associated timestamps (only in the WithTime variants)
- Semantic versioning, via github.com/hashicorp/go-version
- A "guerrilla" comparison for version-like strings that break semver rules
- A plain lexicographic string comparison
Index ¶
- func Compare(v1, v2 string) int
- func CompareWithTime(v1CreateTime, v2CreateTime *time.Time, v1, v2 string) int
- func Equal(v1, v2 string) bool
- func EqualWithTime(v1CreateTime, v2CreateTime *time.Time, v1, v2 string) bool
- func GreaterThan(v1, v2 string) bool
- func GreaterThanOrEqual(v1, v2 string) bool
- func GreaterThanOrEqualWithTime(v1CreateTime, v2CreateTime *time.Time, v1, v2 string) bool
- func GreaterThanWithTime(v1CreateTime, v2CreateTime *time.Time, v1, v2 string) bool
- func LessThan(v1, v2 string) bool
- func LessThanOrEqual(v1, v2 string) bool
- func LessThanOrEqualWithTime(v1CreateTime, v2CreateTime *time.Time, v1, v2 string) bool
- func LessThanWithTime(v1CreateTime, v2CreateTime *time.Time, v1, v2 string) bool
- func Max(versions ...string) string
- func Min(versions ...string) string
- func Sort(versions []string)
- func SortDescending(versions []string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶ added in v0.2.0
Compare compares two version strings.
It returns -1 if v1 sorts before v2, 0 if they are considered equal, and +1 if v1 sorts after v2. Comparison never errors: values that are not valid semantic versions fall back to the guerrilla and string strategies described in the package documentation.
func CompareWithTime ¶ added in v0.2.0
CompareWithTime compares two versions, giving precedence to their associated timestamps (such as create times) when both are present, non-zero, and distinct. Otherwise it falls back to Compare.
It returns -1, 0, or +1, following the same convention as Compare.
func Equal ¶ added in v0.2.0
Equal reports whether v1 and v2 are considered equal. Note that semantic versions are compared semantically, so "1.0" and "1.0.0" are equal.
func EqualWithTime ¶ added in v0.2.0
EqualWithTime reports whether v1 and v2 are considered equal, giving precedence to the associated timestamps when both are present, non-zero, and distinct.
func GreaterThan ¶ added in v0.2.0
GreaterThan reports whether v1 sorts after v2. See the package documentation for the comparison precedence.
func GreaterThanOrEqual ¶ added in v0.2.0
GreaterThanOrEqual reports whether v1 sorts after or equal to v2. See the package documentation for the comparison precedence.
func GreaterThanOrEqualWithTime ¶ added in v0.2.0
GreaterThanOrEqualWithTime reports whether v1 sorts after or equal to v2, giving precedence to the associated timestamps when both are present, non-zero, and distinct.
func GreaterThanWithTime ¶ added in v0.2.0
GreaterThanWithTime reports whether v1 sorts after v2, giving precedence to the associated timestamps when both are present, non-zero, and distinct.
func LessThan ¶
LessThan reports whether v1 sorts before v2. See the package documentation for the comparison precedence.
func LessThanOrEqual ¶ added in v0.2.0
LessThanOrEqual reports whether v1 sorts before or equal to v2. See the package documentation for the comparison precedence.
func LessThanOrEqualWithTime ¶ added in v0.2.0
LessThanOrEqualWithTime reports whether v1 sorts before or equal to v2, giving precedence to the associated timestamps when both are present, non-zero, and distinct.
func LessThanWithTime ¶
LessThanWithTime reports whether v1 sorts before v2, giving precedence to the associated timestamps when both are present, non-zero, and distinct. See the package documentation for the comparison precedence.
func Max ¶ added in v0.2.0
Max returns the greatest of the given versions, using Compare. If no versions are given, it returns the empty string. When several versions compare equal, the first of them is returned.
func Min ¶ added in v0.2.0
Min returns the least of the given versions, using Compare. If no versions are given, it returns the empty string. When several versions compare equal, the first of them is returned.
func Sort ¶ added in v0.2.0
func Sort(versions []string)
Sort sorts a slice of version strings in ascending order, in place, using Compare. Versions that compare equal keep their original relative order.
func SortDescending ¶ added in v0.2.0
func SortDescending(versions []string)
SortDescending sorts a slice of version strings in descending order, in place, using Compare. Versions that compare equal keep their original relative order.
Types ¶
This section is empty.