Skip to content

Commit 82cf8bc

Browse files
committed
cmd/go: add GOPRIVATE environment variable
It is too confusing to have to set GONOSUMDB and GONOPROXY in common use cases, but one cannot be guaranteed to be a subset of the other. This CL adds GOPRIVATE, which takes the same kind of pattern list but is defined as "these patterns are private (non-public) modules". Today the implication is that GOPRIVATE is the default setting for GONOSUMDB and GONOPROXY. If there are other accommodations to make for private packages in the future or in other tools, having this clear statement of intent will let us do that. (For example maybe an IDE integration would hyperlink an import path to godoc.org; consulting GOPRIVATE would be a reasonable way to decide not to do that for certain imports. In contrast, consulting GONOPROXY or GONOSUMDB clearly would not.) Fixes #32184. Change-Id: If54c12d353c7a0a5c0e0273764140cce3c154a02 Reviewed-on: https://go-review.googlesource.com/c/go/+/181719 Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent f44404e commit 82cf8bc

File tree

10 files changed

+212
-174
lines changed

10 files changed

+212
-174
lines changed

src/cmd/go/alldocs.go

Lines changed: 137 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/cfg/cfg.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ var knownEnv = `
265265
GOOS
266266
GOPATH
267267
GOPPC64
268+
GOPRIVATE
268269
GOPROXY
269270
GOROOT
270271
GOSUMDB
@@ -291,30 +292,13 @@ var (
291292
GOPPC64 = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", objabi.GOPPC64))
292293
GOWASM = envOr("GOWASM", fmt.Sprint(objabi.GOWASM))
293294

294-
GOPROXY = goproxy()
295-
GOSUMDB = gosumdb()
296-
GONOPROXY = Getenv("GONOPROXY")
297-
GONOSUMDB = Getenv("GONOSUMDB")
295+
GOPROXY = envOr("GOPROXY", "https://proxy.golang.org,direct")
296+
GOSUMDB = envOr("GOSUMDB", "sum.golang.org")
297+
GOPRIVATE = Getenv("GOPRIVATE")
298+
GONOPROXY = envOr("GONOPROXY", GOPRIVATE)
299+
GONOSUMDB = envOr("GONOSUMDB", GOPRIVATE)
298300
)
299301

300-
func goproxy() string {
301-
v := Getenv("GOPROXY")
302-
if v != "" {
303-
return v
304-
}
305-
306-
return "https://proxy.golang.org,direct"
307-
}
308-
309-
func gosumdb() string {
310-
v := Getenv("GOSUMDB")
311-
if v != "" {
312-
return v
313-
}
314-
315-
return "sum.golang.org"
316-
}
317-
318302
// GetArchEnv returns the name and setting of the
319303
// GOARCH-specific architecture environment variable.
320304
// If the current architecture has no GOARCH-specific variable,

src/cmd/go/internal/envcmd/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func MkEnv() []cfg.EnvVar {
7979
{Name: "GONOSUMDB", Value: cfg.GONOSUMDB},
8080
{Name: "GOOS", Value: cfg.Goos},
8181
{Name: "GOPATH", Value: cfg.BuildContext.GOPATH},
82+
{Name: "GOPRIVATE", Value: cfg.GOPRIVATE},
8283
{Name: "GOPROXY", Value: cfg.GOPROXY},
8384
{Name: "GOROOT", Value: cfg.GOROOT},
8485
{Name: "GOSUMDB", Value: cfg.GOSUMDB},

src/cmd/go/internal/help/helpdoc.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,16 @@ General-purpose environment variables:
510510
For more details see: 'go help gopath'.
511511
GOPROXY
512512
URL of Go module proxy. See 'go help modules'.
513-
GONOPROXY
513+
GOPRIVATE, GONOPROXY, GONOSUMDB
514514
Comma-separated list of glob patterns (in the syntax of Go's path.Match)
515-
of module path prefixes that should always be fetched directly, ignoring
516-
the GOPROXY setting. See 'go help modules'.
515+
of module path prefixes that should always be fetched directly
516+
or that should not be compared against the checksum database.
517+
See 'go help module-private'.
518+
GOROOT
519+
The root of the go tree.
517520
GOSUMDB
518521
The name of checksum database to use and optionally its public key and
519522
URL. See 'go help module-auth'.
520-
GONOSUMDB
521-
Comma-separated list of glob patterns (in the syntax of Go's path.Match)
522-
of module path prefixes that should not be compared against the checksum
523-
database. See 'go help module-auth'.
524-
GOROOT
525-
The root of the go tree.
526523
GOTMPDIR
527524
The directory where the go command will write
528525
temporary source files, packages, and binaries.

0 commit comments

Comments
 (0)