github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/modfetch/fetch.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package modfetch 6 7 import ( 8 "github.com/shogo82148/std/context" 9 "github.com/shogo82148/std/errors" 10 11 "github.com/shogo82148/std/cmd/go/internal/base" 12 13 "golang.org/x/mod/module" 14 ) 15 16 var ErrToolchain = errors.New("internal error: invalid operation on toolchain module") 17 18 // Download downloads the specific module version to the 19 // local download cache and returns the name of the directory 20 // corresponding to the root of the module's file tree. 21 func Download(ctx context.Context, mod module.Version) (dir string, err error) 22 23 // DownloadZip downloads the specific module version to the 24 // local zip cache and returns the name of the zip file. 25 func DownloadZip(ctx context.Context, mod module.Version) (zipfile string, err error) 26 27 // RemoveAll removes a directory written by Download or Unzip, first applying 28 // any permission changes needed to do so. 29 func RemoveAll(dir string) error 30 31 var GoSumFile string 32 var WorkspaceGoSumFiles []string 33 34 // Reset resets globals in the modfetch package, so previous loads don't affect 35 // contents of go.sum files. 36 func Reset() 37 38 // HaveSum returns true if the go.sum file contains an entry for mod. 39 // The entry's hash must be generated with a known hash algorithm. 40 // mod.Version may have a "/go.mod" suffix to distinguish sums for 41 // .mod and .zip files. 42 func HaveSum(mod module.Version) bool 43 44 // RecordedSum returns the sum if the go.sum file contains an entry for mod. 45 // The boolean reports true if an entry was found or 46 // false if no entry found or two conflicting sums are found. 47 // The entry's hash must be generated with a known hash algorithm. 48 // mod.Version may have a "/go.mod" suffix to distinguish sums for 49 // .mod and .zip files. 50 func RecordedSum(mod module.Version) (sum string, ok bool) 51 52 // Sum returns the checksum for the downloaded copy of the given module, 53 // if present in the download cache. 54 func Sum(ctx context.Context, mod module.Version) string 55 56 var ErrGoSumDirty = errors.New("updates to go.sum needed, disabled by -mod=readonly") 57 58 // WriteGoSum writes the go.sum file if it needs to be updated. 59 // 60 // keep is used to check whether a newly added sum should be saved in go.sum. 61 // It should have entries for both module content sums and go.mod sums 62 // (version ends with "/go.mod"). Existing sums will be preserved unless they 63 // have been marked for deletion with TrimGoSum. 64 func WriteGoSum(ctx context.Context, keep map[module.Version]bool, readonly bool) error 65 66 // TrimGoSum trims go.sum to contain only the modules needed for reproducible 67 // builds. 68 // 69 // keep is used to check whether a sum should be retained in go.mod. It should 70 // have entries for both module content sums and go.mod sums (version ends 71 // with "/go.mod"). 72 func TrimGoSum(keep map[module.Version]bool) 73 74 var HelpModuleAuth = &base.Command{ 75 UsageLine: "module-auth", 76 Short: "module authentication using go.sum", 77 Long: ` 78 When the go command downloads a module zip file or go.mod file into the 79 module cache, it computes a cryptographic hash and compares it with a known 80 value to verify the file hasn't changed since it was first downloaded. Known 81 hashes are stored in a file in the module root directory named go.sum. Hashes 82 may also be downloaded from the checksum database depending on the values of 83 GOSUMDB, GOPRIVATE, and GONOSUMDB. 84 85 For details, see https://golang.org/ref/mod#authenticating. 86 `, 87 } 88 89 var HelpPrivate = &base.Command{ 90 UsageLine: "private", 91 Short: "configuration for downloading non-public code", 92 Long: ` 93 The go command defaults to downloading modules from the public Go module 94 mirror at proxy.golang.org. It also defaults to validating downloaded modules, 95 regardless of source, against the public Go checksum database at sum.golang.org. 96 These defaults work well for publicly available source code. 97 98 The GOPRIVATE environment variable controls which modules the go command 99 considers to be private (not available publicly) and should therefore not use 100 the proxy or checksum database. The variable is a comma-separated list of 101 glob patterns (in the syntax of Go's path.Match) of module path prefixes. 102 For example, 103 104 GOPRIVATE=*.corp.example.com,rsc.io/private 105 106 causes the go command to treat as private any module with a path prefix 107 matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private, 108 and rsc.io/private/quux. 109 110 For fine-grained control over module download and validation, the GONOPROXY 111 and GONOSUMDB environment variables accept the same kind of glob list 112 and override GOPRIVATE for the specific decision of whether to use the proxy 113 and checksum database, respectively. 114 115 For example, if a company ran a module proxy serving private modules, 116 users would configure go using: 117 118 GOPRIVATE=*.corp.example.com 119 GOPROXY=proxy.example.com 120 GONOPROXY=none 121 122 The GOPRIVATE variable is also used to define the "public" and "private" 123 patterns for the GOVCS variable; see 'go help vcs'. For that usage, 124 GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths 125 instead of module paths. 126 127 The 'go env -w' command (see 'go help env') can be used to set these variables 128 for future go command invocations. 129 130 For more details, see https://golang.org/ref/mod#private-modules. 131 `, 132 }