Skip to content

Commit cd6f3a5

Browse files
author
Jay Conrod
committed
cmd/go: revise 'go help' documentation for modules
Module-related help pages now contain a brief summary and point to the reference documentation at golang.org/ref/mod for details. Help pages for commands like 'go get' still describe the basic usage and summarize flags but don't provide as much background detail. Fixes #41427 Fixes #43419 Change-Id: Icacd38e0f33c352c447cc5a496c99674493abde2 Reviewed-on: https://go-review.googlesource.com/c/go/+/282615 Trust: Jay Conrod <[email protected]> Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 6192b98 commit cd6f3a5

File tree

16 files changed

+212
-1448
lines changed

16 files changed

+212
-1448
lines changed

src/cmd/go/alldocs.go

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

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ listed in the GOPATH environment variable.
266266
(See 'go help gopath-get' and 'go help gopath'.)
267267
268268
When using modules, downloaded packages are stored in the module cache.
269-
(See 'go help module-get' and 'go help goproxy'.)
269+
See https://golang.org/ref/mod#module-cache.
270270
271271
When using modules, an additional variant of the go-import meta tag is
272272
recognized and is preferred over those listing version control systems.
@@ -276,7 +276,8 @@ That variant uses "mod" as the vcs in the content value, as in:
276276
277277
This tag means to fetch modules with paths beginning with example.org
278278
from the module proxy available at the URL https://code.org/moduleproxy.
279-
See 'go help goproxy' for details about the proxy protocol.
279+
See https://golang.org/ref/mod#goproxy-protocol for details about the
280+
proxy protocol.
280281
281282
Import path checking
282283
@@ -483,6 +484,10 @@ See 'go help env' for details.
483484
484485
General-purpose environment variables:
485486
487+
GO111MODULE
488+
Controls whether the go command runs in module-aware mode or GOPATH mode.
489+
May be "off", "on", or "auto".
490+
See https://golang.org/ref/mod#mod-commands.
486491
GCCGO
487492
The gccgo command to run for 'go build -compiler=gccgo'.
488493
GOARCH
@@ -521,20 +526,24 @@ General-purpose environment variables:
521526
GOPATH
522527
For more details see: 'go help gopath'.
523528
GOPROXY
524-
URL of Go module proxy. See 'go help modules'.
529+
URL of Go module proxy. See https://golang.org/ref/mod#environment-variables
530+
and https://golang.org/ref/mod#module-proxy for details.
525531
GOPRIVATE, GONOPROXY, GONOSUMDB
526532
Comma-separated list of glob patterns (in the syntax of Go's path.Match)
527533
of module path prefixes that should always be fetched directly
528534
or that should not be compared against the checksum database.
529-
See 'go help private'.
535+
See https://golang.org/ref/mod#private-modules.
530536
GOROOT
531537
The root of the go tree.
532538
GOSUMDB
533539
The name of checksum database to use and optionally its public key and
534-
URL. See 'go help module-auth'.
540+
URL. See https://golang.org/ref/mod#authenticating.
535541
GOTMPDIR
536542
The directory where the go command will write
537543
temporary source files, packages, and binaries.
544+
GOVCS
545+
Lists version control commands that may be used with matching servers.
546+
See 'go help vcs'.
538547
539548
Environment variables for use with cgo:
540549

src/cmd/go/internal/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ For more about build flags, see 'go help build'.
304304
305305
For more about specifying packages, see 'go help packages'.
306306
307-
For more about modules, see 'go help modules'.
307+
For more about modules, see https://golang.org/ref/mod.
308308
`,
309309
}
310310

src/cmd/go/internal/modcmd/download.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ corresponding to this Go struct:
5252
5353
The -x flag causes download to print the commands download executes.
5454
55-
See 'go help modules' for more about module queries.
55+
See https://golang.org/ref/mod#go-mod-download for more about 'go mod download'.
56+
57+
See https://golang.org/ref/mod#version-queries for more about version queries.
5658
`,
5759
}
5860

src/cmd/go/internal/modcmd/edit.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ Note that this only describes the go.mod file itself, not other modules
122122
referred to indirectly. For the full set of modules available to a build,
123123
use 'go list -m -json all'.
124124
125-
For example, a tool can obtain the go.mod as a data structure by
126-
parsing the output of 'go mod edit -json' and can then make changes
127-
by invoking 'go mod edit' with -require, -exclude, and so on.
125+
See https://golang.org/ref/mod#go-mod-edit for more about 'go mod edit'.
128126
`,
129127
}
130128

src/cmd/go/internal/modcmd/graph.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Graph prints the module requirement graph (with replacements applied)
2626
in text form. Each line in the output has two space-separated fields: a module
2727
and one of its requirements. Each module is identified as a string of the form
2828
path@version, except for the main module, which has no @version suffix.
29+
30+
See https://golang.org/ref/mod#go-mod-graph for more about 'go mod graph'.
2931
`,
3032
Run: runGraph,
3133
}

src/cmd/go/internal/modcmd/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Gopkg.lock), and the current directory (if in GOPATH).
2727
2828
If a configuration file for a vendoring tool is present, init will attempt to
2929
import module requirements from it.
30+
31+
See https://golang.org/ref/mod#go-mod-init for more about 'go mod init'.
3032
`,
3133
Run: runInit,
3234
}

src/cmd/go/internal/modcmd/tidy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ to standard error.
2929
3030
The -e flag causes tidy to attempt to proceed despite errors
3131
encountered while loading packages.
32+
33+
See https://golang.org/ref/mod#go-mod-tidy for more about 'go mod tidy'.
3234
`,
3335
Run: runTidy,
3436
}

src/cmd/go/internal/modcmd/vendor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ modules and packages to standard error.
3838
3939
The -e flag causes vendor to attempt to proceed despite errors
4040
encountered while loading packages.
41+
42+
See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
4143
`,
4244
Run: runVendor,
4345
}

src/cmd/go/internal/modcmd/verify.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ modified since being downloaded. If all the modules are unmodified,
3131
verify prints "all modules verified." Otherwise it reports which
3232
modules have been changed and causes 'go mod' to exit with a
3333
non-zero status.
34+
35+
See https://golang.org/ref/mod#go-mod-verify for more about 'go mod verify'.
3436
`,
3537
Run: runVerify,
3638
}

src/cmd/go/internal/modcmd/why.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ For example:
4848
# golang.org/x/text/encoding
4949
(main module does not need package golang.org/x/text/encoding)
5050
$
51+
52+
See https://golang.org/ref/mod#go-mod-why for more about 'go mod why'.
5153
`,
5254
}
5355

src/cmd/go/internal/modfetch/fetch.go

Lines changed: 12 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -768,90 +768,14 @@ var HelpModuleAuth = &base.Command{
768768
UsageLine: "module-auth",
769769
Short: "module authentication using go.sum",
770770
Long: `
771-
The go command tries to authenticate every downloaded module,
772-
checking that the bits downloaded for a specific module version today
773-
match bits downloaded yesterday. This ensures repeatable builds
774-
and detects introduction of unexpected changes, malicious or not.
775-
776-
In each module's root, alongside go.mod, the go command maintains
777-
a file named go.sum containing the cryptographic checksums of the
778-
module's dependencies.
779-
780-
The form of each line in go.sum is three fields:
781-
782-
<module> <version>[/go.mod] <hash>
783-
784-
Each known module version results in two lines in the go.sum file.
785-
The first line gives the hash of the module version's file tree.
786-
The second line appends "/go.mod" to the version and gives the hash
787-
of only the module version's (possibly synthesized) go.mod file.
788-
The go.mod-only hash allows downloading and authenticating a
789-
module version's go.mod file, which is needed to compute the
790-
dependency graph, without also downloading all the module's source code.
791-
792-
The hash begins with an algorithm prefix of the form "h<N>:".
793-
The only defined algorithm prefix is "h1:", which uses SHA-256.
794-
795-
Module authentication failures
796-
797-
The go command maintains a cache of downloaded packages and computes
798-
and records the cryptographic checksum of each package at download time.
799-
In normal operation, the go command checks the main module's go.sum file
800-
against these precomputed checksums instead of recomputing them on
801-
each command invocation. The 'go mod verify' command checks that
802-
the cached copies of module downloads still match both their recorded
803-
checksums and the entries in go.sum.
804-
805-
In day-to-day development, the checksum of a given module version
806-
should never change. Each time a dependency is used by a given main
807-
module, the go command checks its local cached copy, freshly
808-
downloaded or not, against the main module's go.sum. If the checksums
809-
don't match, the go command reports the mismatch as a security error
810-
and refuses to run the build. When this happens, proceed with caution:
811-
code changing unexpectedly means today's build will not match
812-
yesterday's, and the unexpected change may not be beneficial.
813-
814-
If the go command reports a mismatch in go.sum, the downloaded code
815-
for the reported module version does not match the one used in a
816-
previous build of the main module. It is important at that point
817-
to find out what the right checksum should be, to decide whether
818-
go.sum is wrong or the downloaded code is wrong. Usually go.sum is right:
819-
you want to use the same code you used yesterday.
820-
821-
If a downloaded module is not yet included in go.sum and it is a publicly
822-
available module, the go command consults the Go checksum database to fetch
823-
the expected go.sum lines. If the downloaded code does not match those
824-
lines, the go command reports the mismatch and exits. Note that the
825-
database is not consulted for module versions already listed in go.sum.
826-
827-
If a go.sum mismatch is reported, it is always worth investigating why
828-
the code downloaded today differs from what was downloaded yesterday.
829-
830-
The GOSUMDB environment variable identifies the name of checksum database
831-
to use and optionally its public key and URL, as in:
832-
833-
GOSUMDB="sum.golang.org"
834-
GOSUMDB="sum.golang.org+<publickey>"
835-
GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"
836-
837-
The go command knows the public key of sum.golang.org, and also that the name
838-
sum.golang.google.cn (available inside mainland China) connects to the
839-
sum.golang.org checksum database; use of any other database requires giving
840-
the public key explicitly.
841-
The URL defaults to "https://" followed by the database name.
842-
843-
GOSUMDB defaults to "sum.golang.org", the Go checksum database run by Google.
844-
See https://sum.golang.org/privacy for the service's privacy policy.
845-
846-
If GOSUMDB is set to "off", or if "go get" is invoked with the -insecure flag,
847-
the checksum database is not consulted, and all unrecognized modules are
848-
accepted, at the cost of giving up the security guarantee of verified repeatable
849-
downloads for all modules. A better way to bypass the checksum database
850-
for specific modules is to use the GOPRIVATE or GONOSUMDB environment
851-
variables. See 'go help private' for details.
852-
853-
The 'go env -w' command (see 'go help env') can be used to set these variables
854-
for future go command invocations.
771+
When the go command downloads a module zip file or go.mod file into the
772+
module cache, it computes a cryptographic hash and compares it with a known
773+
value to verify the file hasn't changed since it was first downloaded. Known
774+
hashes are stored in a file in the module root directory named go.sum. Hashes
775+
may also be downloaded from the checksum database depending on the values of
776+
GOSUMDB, GOPRIVATE, and GONOSUMDB.
777+
778+
For details, see https://golang.org/ref/mod#authenticating.
855779
`,
856780
}
857781

@@ -865,8 +789,8 @@ regardless of source, against the public Go checksum database at sum.golang.org.
865789
These defaults work well for publicly available source code.
866790
867791
The GOPRIVATE environment variable controls which modules the go command
868-
considers to be private (not available publicly) and should therefore not use the
869-
proxy or checksum database. The variable is a comma-separated list of
792+
considers to be private (not available publicly) and should therefore not use
793+
the proxy or checksum database. The variable is a comma-separated list of
870794
glob patterns (in the syntax of Go's path.Match) of module path prefixes.
871795
For example,
872796
@@ -876,10 +800,6 @@ causes the go command to treat as private any module with a path prefix
876800
matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private,
877801
and rsc.io/private/quux.
878802
879-
The GOPRIVATE environment variable may be used by other tools as well to
880-
identify non-public modules. For example, an editor could use GOPRIVATE
881-
to decide whether to hyperlink a package import to a godoc.org page.
882-
883803
For fine-grained control over module download and validation, the GONOPROXY
884804
and GONOSUMDB environment variables accept the same kind of glob list
885805
and override GOPRIVATE for the specific decision of whether to use the proxy
@@ -892,18 +812,14 @@ users would configure go using:
892812
GOPROXY=proxy.example.com
893813
GONOPROXY=none
894814
895-
This would tell the go command and other tools that modules beginning with
896-
a corp.example.com subdomain are private but that the company proxy should
897-
be used for downloading both public and private modules, because
898-
GONOPROXY has been set to a pattern that won't match any modules,
899-
overriding GOPRIVATE.
900-
901815
The GOPRIVATE variable is also used to define the "public" and "private"
902816
patterns for the GOVCS variable; see 'go help vcs'. For that usage,
903817
GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
904818
instead of module paths.
905819
906820
The 'go env -w' command (see 'go help env') can be used to set these variables
907821
for future go command invocations.
822+
823+
For more details, see https://golang.org/ref/mod#private-modules.
908824
`,
909825
}

src/cmd/go/internal/modfetch/proxy.go

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,8 @@ URLs of a specified form. The requests have no query parameters, so even
3636
a site serving from a fixed file system (including a file:/// URL)
3737
can be a module proxy.
3838
39-
The GET requests sent to a Go module proxy are:
40-
41-
GET $GOPROXY/<module>/@v/list returns a list of known versions of the given
42-
module, one per line.
43-
44-
GET $GOPROXY/<module>/@v/<version>.info returns JSON-formatted metadata
45-
about that version of the given module.
46-
47-
GET $GOPROXY/<module>/@v/<version>.mod returns the go.mod file
48-
for that version of the given module.
49-
50-
GET $GOPROXY/<module>/@v/<version>.zip returns the zip archive
51-
for that version of the given module.
52-
53-
GET $GOPROXY/<module>/@latest returns JSON-formatted metadata about the
54-
latest known version of the given module in the same format as
55-
<module>/@v/<version>.info. The latest version should be the version of
56-
the module the go command may use if <module>/@v/list is empty or no
57-
listed version is suitable. <module>/@latest is optional and may not
58-
be implemented by a module proxy.
59-
60-
When resolving the latest version of a module, the go command will request
61-
<module>/@v/list, then, if no suitable versions are found, <module>/@latest.
62-
The go command prefers, in order: the semantically highest release version,
63-
the semantically highest pre-release version, and the chronologically
64-
most recent pseudo-version. In Go 1.12 and earlier, the go command considered
65-
pseudo-versions in <module>/@v/list to be pre-release versions, but this is
66-
no longer true since Go 1.13.
67-
68-
To avoid problems when serving from case-sensitive file systems,
69-
the <module> and <version> elements are case-encoded, replacing every
70-
uppercase letter with an exclamation mark followed by the corresponding
71-
lower-case letter: github.com/Azure encodes as github.com/!azure.
72-
73-
The JSON-formatted metadata about a given module corresponds to
74-
this Go data structure, which may be expanded in the future:
75-
76-
type Info struct {
77-
Version string // version string
78-
Time time.Time // commit time
79-
}
80-
81-
The zip archive for a specific version of a given module is a
82-
standard zip file that contains the file tree corresponding
83-
to the module's source code and related files. The archive uses
84-
slash-separated paths, and every file path in the archive must
85-
begin with <module>@<version>/, where the module and version are
86-
substituted directly, not case-encoded. The root of the module
87-
file tree corresponds to the <module>@<version>/ prefix in the
88-
archive.
89-
90-
Even when downloading directly from version control systems,
91-
the go command synthesizes explicit info, mod, and zip files
92-
and stores them in its local cache, $GOPATH/pkg/mod/cache/download,
93-
the same as if it had downloaded them directly from a proxy.
94-
The cache layout is the same as the proxy URL space, so
95-
serving $GOPATH/pkg/mod/cache/download at (or copying it to)
96-
https://example.com/proxy would let other users access those
97-
cached module versions with GOPROXY=https://example.com/proxy.
39+
For details on the GOPROXY protocol, see
40+
https://golang.org/ref/mod#goproxy-protocol.
9841
`,
9942
}
10043

0 commit comments

Comments
 (0)