Private Modules & Proxies
By default the go command fetches every module from the public mirror and checks it against the public checksum database:
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.orgThat's wrong for company code in two ways: the public proxy can't see your private repositories, and asking the checksum database about git.corp.example/payments would leak the name of your private module to a public service. Four environment variables control this.
The variables
| Variable | Meaning | Example |
|---|---|---|
GOPROXY |
comma-separated list of proxies tried in order; direct = fetch from the VCS (Git) yourself; off = no downloads |
https://goproxy.corp.example,https://proxy.golang.org,direct |
GOPRIVATE |
glob patterns of private module path prefixes; the default for the two below | *.corp.example,github.com/acme-private |
GONOPROXY |
modules fetched direct instead of through GOPROXY (defaults to GOPRIVATE) |
none when your proxy serves private modules |
GONOSUMDB |
modules never looked up in the checksum database (defaults to GOPRIVATE) |
|
GOAUTH (Go 1.24+) |
how to authenticate to proxies and VCS hosts (netrc by default, git, or a command) |
git /home/me/src |
The patterns are path prefixes matched element by element with Go's path.Match syntax: *.corp.example matches git.corp.example/team/lib, because its first element matches. Set them once with go env -w GOPRIVATE=*.corp.example (stored in go env GOENV's file), or in CI's environment.
A model of the decision
For each module the go command asks two questions: through the proxy or direct, and check the checksum database or not. This model implements the matching rule:
// Go's rule: a pattern matches if it matches a leading run of path elements (path.Match per element).
function globMatch(pattern, element) {
const re = new RegExp('^' + pattern.split('*').map((s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\amp;')).join('[^/]*') + '