@@ -14,18 +14,85 @@ import (
14
14
"strings"
15
15
"time"
16
16
17
+ "cmd/go/internal/base"
17
18
"cmd/go/internal/modfetch/codehost"
18
19
"cmd/go/internal/module"
19
20
"cmd/go/internal/semver"
20
21
)
21
22
23
+ var HelpGoproxy = & base.Command {
24
+ UsageLine : "goproxy" ,
25
+ Short : "module proxy protocol" ,
26
+ Long : `
27
+ The go command by default downloads modules from version control systems
28
+ directly, just as 'go get' always has. If the GOPROXY environment variable
29
+ is set to the URL of a module proxy, the go command will instead fetch
30
+ all modules from that proxy. No matter the source of the modules, downloaded
31
+ modules must match existing entries in go.sum (see 'go help modules' for
32
+ discussion of verification).
33
+
34
+ A Go module proxy is any web server that can respond to GET requests for
35
+ URLs of a specified form. The requests have no query parameters, so even
36
+ a site serving from a fixed file system (including a file:/// URL)
37
+ can be a module proxy.
38
+
39
+ The GET requests sent to a Go module proxy are:
40
+
41
+ GET $GOPROXY/<module>/@v/list returns a list of all known versions of the
42
+ given 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
+ To avoid problems when serving from case-sensitive file systems,
54
+ the <module> and <version> elements are case-encoded, replacing every
55
+ uppercase letter with an exclamation mark followed by the correponding
56
+ lower-case letter: github.com/Azure encodes as github.com/!azure.
57
+
58
+ The JSON-formatted metadata about a given module corresponds to
59
+ this Go data structure, which may be expanded in the future:
60
+
61
+ type Info struct {
62
+ Version string // version string
63
+ Time time.Time // commit time
64
+ }
65
+
66
+ The zip archive for a specific version of a given module is a
67
+ standard zip file that contains the file tree corresponding
68
+ to the module's source code and related files. The archive uses
69
+ slash-separated paths, and every file path in the archive must
70
+ begin with <module>@<version>/, where the module and version are
71
+ substituted directly, not case-encoded. The root of the module
72
+ file tree corresponds to the <module>@<version>/ prefix in the
73
+ archive.
74
+
75
+ Even when downloading directly from version control systems,
76
+ the go command synthesizes explicit info, mod, and zip files
77
+ and stores them in its local cache, $GOPATH/src/mod/cache/download,
78
+ the same as if it had downloaded them directly from a proxy.
79
+ The cache layout is the same as the proxy URL space, so
80
+ serving $GOPATH/src/mod/cache/download at (or copying it to)
81
+ https://example.com/proxy would let other users access those
82
+ cached module versions with GOPROXY=https://example.com/proxy.
83
+ ` ,
84
+ }
85
+
22
86
var proxyURL = os .Getenv ("GOPROXY" )
23
87
24
88
func lookupProxy (path string ) (Repo , error ) {
89
+ if strings .Contains (proxyURL , "," ) {
90
+ return nil , fmt .Errorf ("invalid $GOPROXY setting: cannot have comma" )
91
+ }
25
92
u , err := url .Parse (proxyURL )
26
93
if err != nil || u .Scheme != "http" && u .Scheme != "https" && u .Scheme != "file" {
27
94
// Don't echo $GOPROXY back in case it has user:password in it (sigh).
28
- return nil , fmt .Errorf ("invalid $GOPROXY setting" )
95
+ return nil , fmt .Errorf ("invalid $GOPROXY setting: malformed URL or invalid scheme (must be http, https, file) " )
29
96
}
30
97
return newProxyRepo (u .String (), path )
31
98
}
0 commit comments