go mod tidy
package path: The path that uniquely identifies a package. A package path is a module path joined with a subdirectory within the module. For example "golang.org/x/net/html" is the package path for the package in the module "golang.org/x/net" in the "html" subdirectory.
A module is a collection of packages that are released, versioned, and distributed together. Modules may be downloaded directly from version control repositories or from module proxy servers.
A module is identified by a module path, which is declared in a go.mod file, together with information about the module’s dependencies. The module root directory is the directory that contains the go.mod file. The main module is the module containing the directory where the go command is invoked.
build list: The list of module versions that will be used for a build command such as go build, go list, or go test. The build list is determined from the main module’sgo.mod file and go.mod files in transitively required modules using minimal version selection. The build list contains versions for all modules in the module graph, not just those relevant to a specific command.
Resolving a package to a module
When the go command loads a package using a package path, it needs to determine which module provides the package.
go mod tidy是 Go 编程语言模块系统中的一个命令。它用于自动管理您的 Go 项目所依赖的模块。
当您运行时go mod tidy,它会做两件主要的事情:
- 它确保您的
go.mod文件包含您的 Go 代码实际需要的所有依赖项。它添加构建当前模块的包和依赖项所需的任何缺少的模块,并删除任何不需要的模块。这意味着如果您在 Go 代码中导入的包尚未在您的go.mod文件中列出,go mod tidy则会添加它。go.mod如果您的文件中列出了您的 Go 代码实际上不需要的模块,go mod tidy则会将其删除 - 它还确保您的
go.sum文件包含项目依赖项所需的所有校验和。您看到的输出 (go: finding module for package rsc.io/quote和go: found rsc.io/quote in rsc.io/quote v1.5.2) 是 Go 的模块系统报告它正在寻找rsc.io/quote您的代码所依赖的包,并且它在rsc.io/quoteversion 的模块中找到了该包v1.5.2。它会根据需要将此模块添加到go.mod和文件中。go.sum