Imports #
"golang.org/x/mod/modfile"
"bytes"
"strings"
"internal/gover"
"internal/goversion"
"runtime"
"strconv"
"sort"
"strings"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
"cmd/go/internal/base"
"context"
"errors"
"fmt"
"strings"
"golang.org/x/mod/modfile"
"bytes"
"strings"
"internal/gover"
"internal/goversion"
"runtime"
"strconv"
"sort"
"strings"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
"cmd/go/internal/base"
"context"
"errors"
"fmt"
"strings"
DefaultGoModVersion is the Go version to assume for go.mod files that do not declare a Go version. The go command has been writing go versions to modules since Go 1.12, so a go.mod without a version is either very old or recently hand-written. Since we can't tell which, we have to assume it's very old. The semantics of the go.mod changed at Go 1.17 to support graph pruning. If see a go.mod without a go line, we have to assume Go 1.16 so that we interpret the requirements correctly. Note that this default must stay at Go 1.16; it cannot be moved forward.
const DefaultGoModVersion = "1.16"
DefaultGoWorkVersion is the Go version to assume for go.work files that do not declare a Go version. Workspaces were added in Go 1.18, so use that.
const DefaultGoWorkVersion = "1.18"
var ErrTooNew = *ast.CallExpr
ExplicitIndirectVersion is the Go version at which a module's go.mod file is expected to list explicit requirements on every module that provides any package transitively imported by that module. Other indirect dependencies of such a module can be safely pruned out of the module graph; see https://golang.org/ref/mod#graph-pruning.
const ExplicitIndirectVersion = "1.17"
ExplicitModulesTxtImportVersion is the Go version at which vendored packages need to be present in modules.txt to be imported.
const ExplicitModulesTxtImportVersion = "1.23"
goStrictVersion is the Go version at which the Go versions became "strict" in the sense that, restricted to modules at this version or later, every module must have a go version line ≥ all its dependencies. It is also the version after which "too new" a version is considered a fatal error.
const GoStrictVersion = "1.21"
narrowAllVersion is the Go version at which the module-module "all" pattern no longer closes over the dependencies of tests outside of the main module.
const NarrowAllVersion = "1.16"
separateIndirectVersion is the Go version at which "// indirect" dependencies are added in a block separate from the direct ones. See https://golang.org/issue/45965.
const SeparateIndirectVersion = "1.17"
Startup records the information that went into the startup-time version switch. It is initialized by switchGoToolchain.
var Startup struct{...}
TestVersion is initialized in the go command test binary to be $TESTGO_VERSION, to allow tests to override the go command's idea of its own version as returned by Local.
var TestVersion string
tidyGoModSumVersion is the Go version at which 'go mod tidy' preserves go.mod checksums needed to build test dependencies of packages in "all", so that 'go test all' can be run without checksum errors. See https://go.dev/issue/56222.
const TidyGoModSumVersion = "1.21"
var nl = *ast.CallExpr
A Switcher provides the ability to switch to a new toolchain in response to TooNewErrors. See [cmd/go/internal/toolchain.Switcher] for documentation.
type Switcher interface {
Error(err error)
Switch(ctx context.Context)
}
A TooNewError explains that a module is too new for this version of Go.
type TooNewError struct {
What string
GoVersion string
Toolchain string
}
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
func (e *TooNewError) Error() string
FromGoMod returns the go version from the go.mod file. It returns DefaultGoModVersion if the go.mod file does not contain a go line or if mf is nil.
func FromGoMod(mf *modfile.File) string
FromGoWork returns the go version from the go.mod file. It returns DefaultGoWorkVersion if the go.mod file does not contain a go line or if wf is nil.
func FromGoWork(wf *modfile.WorkFile) string
FromToolchain returns the Go version for the named toolchain, derived from the name itself (not by running the toolchain). A toolchain is named "goVERSION". A suffix after the VERSION introduced by a -, space, or tab is removed. Examples: FromToolchain("go1.2.3") == "1.2.3" FromToolchain("go1.2.3-bigcorp") == "1.2.3" FromToolchain("invalid") == ""
func FromToolchain(name string) string
GoModLookup takes go.mod or go.work content, finds the first line in the file starting with the given key, and returns the value associated with that key. Lookup should only be used with non-factored verbs such as "go" and "toolchain", usually to find versions or version-like strings.
func GoModLookup(gomod []byte, key string) string
func (e *TooNewError) Is(err error) bool
IsLang reports whether v denotes the overall Go language version and not a specific release. Starting with the Go 1.21 release, "1.x" denotes the overall language version; the first release is "1.x.0". The distinction is important because the relative ordering is 1.21 < 1.21rc1 < 1.21.0 meaning that Go 1.21rc1 and Go 1.21.0 will both handle go.mod files that say "go 1.21", but Go 1.21rc1 will not handle files that say "go 1.21.0".
func IsLang(x string) bool
IsPrerelease reports whether v denotes a Go prerelease version.
func IsPrerelease(x string) bool
IsToolchain reports whether the module path corresponds to the virtual, non-downloadable module tracking go or toolchain directives in the go.mod file. Note that IsToolchain only matches "go" and "toolchain", not the real, downloadable module "golang.org/toolchain" containing toolchain files. IsToolchain("go") = true IsToolchain("toolchain") = true IsToolchain("golang.org/x/tools") = false IsToolchain("golang.org/toolchain") = false
func IsToolchain(path string) 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
Local returns the local Go version, the one implemented by this go command.
func Local() string
LocalToolchain returns the local toolchain name, the one implemented by this go command.
func LocalToolchain() string
Max returns the maximum of x and y interpreted as toolchain versions, compared using Compare. If x and y compare equal, Max returns x.
func Max(x string, y string) string
ModCompare returns the result of comparing the versions x and y for the module with the given path. The path is necessary because the "go" and "toolchain" modules use a different version syntax and semantics (gover, this package) than most modules (semver).
func ModCompare(path string, x string, y string) int
ModIsPrefix reports whether v is a valid version syntax prefix for the module with the given path. The caller is assumed to have checked that ModIsValid(path, vers) is true.
func ModIsPrefix(path string, vers string) bool
ModIsPrerelease reports whether v is a prerelease version for the module with the given path. The caller is assumed to have checked that ModIsValid(path, vers) is true.
func ModIsPrerelease(path string, vers string) bool
ModIsValid reports whether vers is a valid version syntax for the module with the given path.
func ModIsValid(path string, vers string) bool
ModMajorMinor returns the "major.minor" truncation of the version v, for use as a prefix in "@patch" queries.
func ModMajorMinor(path string, vers string) string
ModSort is like module.Sort but understands the "go" and "toolchain" modules and their version ordering.
func ModSort(list []module.Version)
Prev returns the Go major release immediately preceding v, or v itself if v is the first Go major release (1.0) or not a supported Go version. Examples: Prev("1.2") = "1.1" Prev("1.3rc4") = "1.2"
func Prev(x string) string
ToolchainMax returns the maximum of x and y interpreted as toolchain names, compared using Compare(FromToolchain(x), FromToolchain(y)). If x and y compare equal, Max returns x.
func ToolchainMax(x string, y string) string
func local() (goVers string, toolVers string)
func maybeToolchainVersion(name string) string
func parseKey(line []byte, key string) (string, bool)
Generated with Arrow