type Switcher … // Error reports the error to the Switcher, // which saves it for processing during Switch. func (s *Switcher) Error(err error) { … } // addTooNew adds any TooNew errors that can be found in err. func (s *Switcher) addTooNew(err error) { … } // NeedSwitch reports whether Switch would attempt to switch toolchains. func (s *Switcher) NeedSwitch() bool { … } // Switch decides whether to switch to a newer toolchain // to resolve any of the saved errors. // It switches if toolchain switches are permitted and there is at least one TooNewError. // // If Switch decides not to switch toolchains, it prints the errors using base.Error and returns. // // If Switch decides to switch toolchains but cannot identify a toolchain to use. // it prints the errors along with one more about not being able to find the toolchain // and returns. // // Otherwise, Switch prints an informational message giving a reason for the // switch and the toolchain being invoked and then switches toolchains. // This operation never returns. func (s *Switcher) Switch(ctx context.Context) { … } var counterSwitchExec … // SwitchOrFatal attempts a toolchain switch based on the information in err // and otherwise falls back to base.Fatal(err). func SwitchOrFatal(ctx context.Context, err error) { … } // NewerToolchain returns the name of the toolchain to use when we need // to switch to a newer toolchain that must support at least the given Go version. // See https://go.dev/doc/toolchain#switch. // // If the latest major release is 1.N.0, we use the latest patch release of 1.(N-1) if that's >= version. // Otherwise we use the latest 1.N if that's allowed. // Otherwise we use the latest release. func NewerToolchain(ctx context.Context, version string) (string, error) { … } // autoToolchains returns the list of toolchain versions available to GOTOOLCHAIN=auto or =min+auto mode. func autoToolchains(ctx context.Context) ([]string, error) { … } // pathToolchains returns the list of toolchain versions available to GOTOOLCHAIN=path or =min+path mode. func pathToolchains(ctx context.Context) ([]string, error) { … } // newerToolchain implements NewerToolchain where the list of choices is known. // It is separated out for easier testing of this logic. func newerToolchain(need string, list []string) (string, error) { … } // HasAuto reports whether the GOTOOLCHAIN setting allows "auto" upgrades. func HasAuto() bool { … } // HasPath reports whether the GOTOOLCHAIN setting allows "path" upgrades. func HasPath() bool { … }