go mod tidy
The go subcommand that adds any module your code imports but go.mod lacks, and removes any it lists but no longer uses.
In more detail
It rewrites go.mod (and its checksum file go.sum) to match the code as it is now. Run it before committing so the dependency list is honest. A pipeline can run it and fail if the files change, which catches a forgotten tidy.
Example
go mod tidyRelated terms
- go.mod — The text file at the root of a Go module that records its module path, the Go version it needs and the other modules it depends on.
- go mod vendor — The go subcommand that copies the source of every dependency into a vendor folder inside your module, so builds need no network.
- dependency — Anything a program needs in order to work, such as a library, a tool or another service.
Taught in
- Go Workspaces and Modules — Concurrent Systems Programming with Go