Documentation
¶
Overview ¶
Package gover provides operations on Go versions in Go toolchain name syntax: strings like "go1.20", "go1.21.0", "go1.22rc2", and "go1.23.4-bigcorp".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CmpInt ¶
CmpInt returns cmp.Compare(x, y) interpreting x and y as decimal numbers. (Copied from golang.org/x/mod/semver's compareInt.)
func Compare ¶
Compare returns -1, 0, or +1 depending on whether x < y, x == y, or x > y, interpreted as Go versions. The versions x and y must begin with a "go" prefix: "go1.21" not "1.21". Invalid versions, including the empty string, compare less than valid versions and equal to each other. After go1.21, the language version is less than specific release versions or other prerelease versions. For example:
Compare("go1.21rc1", "go1.21") = 1
Compare("go1.21rc1", "go1.21.0") = -1
Compare("go1.22rc1", "go1.22") = 1
Compare("go1.22rc1", "go1.22.0") = -1
However, When the language version is below go1.21, the situation is quite different, because the initial release version was 1.N, not 1.N.0. For example:
Compare("go1.20rc1", "go1.21") = -1
Compare("go1.19rc1", "go1.19") = -1
Compare("go1.18", "go1.18rc1") = 1
Compare("go1.18", "go1.18rc1") = 1
This situation also happens to prerelease for some old patch versions, such as "go1.8.5rc5, "go1.9.2rc2" For example:
Compare("go1.8.5rc4", "go1.8.5rc5") = -1
Compare("go1.8.5rc5", "go1.8.5") = -1
Compare("go1.9.2rc2", "go1.9.2") = -1
Compare("go1.9.2rc2", "go1.9") = 1
func DecInt ¶
DecInt returns the decimal string decremented by 1, or the empty string if the decimal is all zeroes. (Copied from golang.org/x/mod/module's decDecimal.)
Types ¶
type Version ¶
type Version struct {
Major string // decimal
Minor string // decimal or ""
Patch string // decimal or ""
Kind string // "", "alpha", "beta", "rc"
Pre string // decimal or ""
}
A Version is a parsed Go version: major[.Minor[.Patch]][kind[pre]] The numbers are the original decimal strings to avoid integer overflows and since there is very little actual math. (Probably overflow doesn't matter in practice, but at the time this code was written, there was an existing test that used go1.99999999999, which does not fit in an int on 32-bit platforms. The "big decimal" representation avoids the problem entirely.)