Documentation
¶
Overview ¶
Package goproxy provides pure helpers for interpreting the GOPROXY, GOPRIVATE and GONOPROXY environment variables the way the go command itself does. The parsing helpers are pure string -> value transforms; the per-spec module variables (GOPRIVATE and friends) ride on ctx, see WithSpecEnv.
Index ¶
- Constants
- func Disabled(goproxy string) bool
- func Environ(ctx context.Context) []string
- func FirstURL(goproxy string) (string, bool)
- func Getenv(ctx context.Context, key string) string
- func IndexBaseURL(goproxy string) string
- func IsPrivate(modulePath, goprivate, gonoproxy string) bool
- func WithSpecEnv(ctx context.Context, spec map[string]string) context.Context
Constants ¶
const DefaultProxyURL = "https://proxy.golang.org"
DefaultProxyURL is the module proxy the go command falls back to when GOPROXY is unset - https://proxy.golang.org.
Variables ¶
This section is empty.
Functions ¶
func Disabled ¶
Disabled reports whether goproxy's first entry is "off" - module downloading disabled entirely, per the go command's own convention.
func Environ ¶ added in v0.6.2
Environ returns KEY=value for every module variable, always all of them (empty when unset), so a go subprocess sees exactly ctx's values.
func FirstURL ¶
FirstURL returns the first usable http(s) proxy URL named by a GOPROXY-style value. Only the first entry (before any "," or "|") is considered - there is no fallback-entry walking. An empty (or whitespace-only) goproxy reports Go's default proxy. A first entry of "direct", "off", or anything that doesn't parse as an http(s) URL with a host is reported as not-ok; it is up to the caller to decide what to do (fall back to a default, skip a probe, etc).
func Getenv ¶ added in v0.6.2
Getenv returns key's value from ctx's spec environment when ctx carries one (see WithSpecEnv), else the process environment.
func IndexBaseURL ¶
IndexBaseURL returns the base URL to query for the golang.org/toolchain release index: the first usable GOPROXY entry, falling back to Go's default public proxy when GOPROXY's first entry isn't directly usable (e.g. "direct", "off", or a private proxy this process can't reach unauthenticated). The toolchain index is public release metadata, so this fallback carries no privacy concern.
func IsPrivate ¶
IsPrivate reports whether modulePath should be treated as private, mirroring the go command's own precedence rule: when GONOPROXY is non-empty it governs exclusively; GOPRIVATE is only consulted as its default when GONOPROXY is empty. Patterns are matched with module.MatchPrefixPatterns, the same comma-separated glob matcher the go command itself uses for GOPRIVATE/GONOPROXY/GONOSUMCHECK.
func WithSpecEnv ¶ added in v0.6.2
WithSpecEnv returns ctx carrying each module variable as the union of the process environment and spec (a melange spec's environment), comma-joined with empty values skipped, so a spec's private modules are treated as private by every go subprocess and module-name check run for it.
Types ¶
This section is empty.