github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/gover/toolchain.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gover 6 7 import ( 8 "github.com/shogo82148/std/context" 9 "github.com/shogo82148/std/errors" 10 ) 11 12 // FromToolchain returns the Go version for the named toolchain, 13 // derived from the name itself (not by running the toolchain). 14 // A toolchain is named "goVERSION". 15 // A suffix after the VERSION introduced by a -, space, or tab is removed. 16 // Examples: 17 // 18 // FromToolchain("go1.2.3") == "1.2.3" 19 // FromToolchain("go1.2.3-bigcorp") == "1.2.3" 20 // FromToolchain("invalid") == "" 21 func FromToolchain(name string) string 22 23 // ToolchainMax returns the maximum of x and y interpreted as toolchain names, 24 // compared using Compare(FromToolchain(x), FromToolchain(y)). 25 // If x and y compare equal, Max returns x. 26 func ToolchainMax(x, y string) string 27 28 // Startup records the information that went into the startup-time version switch. 29 // It is initialized by switchGoToolchain. 30 var Startup struct { 31 GOTOOLCHAIN string 32 AutoFile string 33 AutoGoVersion string 34 AutoToolchain string 35 } 36 37 // A TooNewError explains that a module is too new for this version of Go. 38 type TooNewError struct { 39 What string 40 GoVersion string 41 Toolchain string 42 } 43 44 func (e *TooNewError) Error() string 45 46 var ErrTooNew = errors.New("module too new") 47 48 func (e *TooNewError) Is(err error) bool 49 50 // A Switcher provides the ability to switch to a new toolchain in response to TooNewErrors. 51 // See [cmd/go/internal/toolchain.Switcher] for documentation. 52 type Switcher interface { 53 Error(err error) 54 Switch(ctx context.Context) 55 }