Imports #
"strings"
"go/ast"
"go/types"
"strings"
"strings"
"go/ast"
"go/types"
"strings"
Future is an invalid unknown Go version sometime in the future. Do not use directly with Compare.
const Future = ""
GoVersions that features in x/tools can be gated to.
const Go1_18 = "go1.18"
GoVersions that features in x/tools can be gated to.
const Go1_19 = "go1.19"
GoVersions that features in x/tools can be gated to.
const Go1_20 = "go1.20"
GoVersions that features in x/tools can be gated to.
const Go1_21 = "go1.21"
GoVersions that features in x/tools can be gated to.
const Go1_22 = "go1.22"
A gover is a parsed Go gover: 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.)
type gover struct {
major string
minor string
patch string
kind string
pre string
}
AtLeast reports whether the file version v comes after a Go release. Use this predicate to enable a behavior once a certain Go release has happened (and stays enabled in the future).
func AtLeast(v string, release string) bool
Before reports whether the file version v is strictly before a Go release. Use this predicate to disable a behavior once a certain Go release has happened (and stays enabled in the future).
func Before(v string, release string) bool
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. The language version "go1.21" compares less than the release candidate and eventual releases "go1.21rc1" and "go1.21.0". Custom toolchain suffixes are ignored during comparison: "go1.21.0" and "go1.21.0-bigcorp" are equal.
func Compare(x string, y string) int
FileVersion returns a file's Go version. The reported version is an unknown Future version if a version cannot be determined.
func FileVersion(info *types.Info, file *ast.File) string
IsValid reports whether the version x is valid.
func IsValid(x string) bool
Lang returns the Go language version for version x. If x is not a valid version, Lang returns the empty string. For example: Lang("go1.21rc2") = "go1.21" Lang("go1.21.2") = "go1.21" Lang("go1.21") = "go1.21" Lang("go1") = "go1" Lang("bad") = "" Lang("1.21") = ""
func Lang(x string) string
cmpInt returns cmp.Compare(x, y) interpreting x and y as decimal numbers. (Copied from golang.org/x/mod/semver's compareInt.)
func cmpInt(x string, y string) int
compare returns -1, 0, or +1 depending on whether x < y, x == y, or x > y, interpreted as toolchain versions. The versions x and y must not begin with a "go" prefix: just "1.21" not "go1.21". Malformed versions compare less than well-formed versions and equal to each other. The language version "1.21" compares less than the release candidate and eventual releases "1.21rc1" and "1.21.0".
func compare(x string, y string) int
cutInt scans the leading decimal number at the start of x to an integer and returns that value and the rest of the string.
func cutInt(x string) (n string, rest string, ok bool)
isValid reports whether the version x is valid.
func isValid(x string) bool
lang returns the Go language version. For example, lang("1.2.3") == "1.2".
func lang(x string) string
parse parses the Go version string x into a version. It returns the zero version if x is malformed.
func parse(x string) gover
stripGo converts from a "go1.21" version to a "1.21" version. If v does not start with "go", stripGo returns the empty string (a known invalid version).
func stripGo(v string) string
Generated with Arrow