go help mod Go mod provides access to operations on modules.
Note that support for modules is built into all the go commands, not just 'go mod'. For example, day-to-day adding, removing, upgrading, and downgrading of dependencies should be done using 'go get'. See 'go help modules'for an overview of module functionality.
go mod <command> [arguments]
The commands are:
download download modules to local cache edit edit go.mod from tools or scripts graph print module requirement graph init initialize new module in current directory tidy add missing and remove unused modules vendor make vendored copy of dependencies verify verify dependencies have expected content why explain why packages or modules are needed
Use "go help mod <command>"for more information about a command.
4.1. go mod init
1 2 3 4 5 6 7 8 9
go help mod init usage: go mod init [module]
Init initializes and writes a new go.mod to the current directory, in effect creating a new module rooted at the current directory. The file go.mod must not already exist. If possible, init will guess the module path from import comments (see 'go help importpath') or from version control configuration. To override this guess, supply the module path as an argument.
4.2. go mod tidy
1 2 3 4 5 6 7 8 9 10
usage: go mod tidy [-v]
Tidy makes sure go.mod matches the source code in the module. It adds any missing modules necessary to build the current module's packages and dependencies, and it removes unused modules that don't provide any relevant packages. It also adds any missing entries to go.sum and removes any unnecessary ones.
The -v flag causes tidy to print information about removed modules to standard error.
4.3. go mod vendor
1 2 3 4 5 6 7 8 9
go help mod vendor usage: go mod vendor [-v]
Vendor resets the main module's vendor directory to include all packages needed to build and test all the main module's packages. It does not include test code for vendored packages.
The -v flag causes vendor to print the names of vendored modules and packages to standard error.