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.
In more detail
go mod init creates it, and commands such as go get and go mod tidy keep it up to date. A diff on go.mod in a pull request is effectively a dependency review. Only one go.mod sits at the root of a module; packages are folders underneath it.
Example
module course.local/probe
go 1.23.12Related terms
- Go module — A tree of Go packages that is versioned and released together, described by a go.mod file at its root.
- go mod init — The go subcommand that starts a new module by writing a go.mod file with the module path you give it.
- 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.
- toolchain directive — Lines in go.mod that state which Go language version a module needs and, optionally, which exact toolchain release should build it.
- replace directive — A line in go.mod that tells the go command to use a different copy of a module, often a folder on your disk, instead of the published version.
Taught in
- Go Workspaces and Modules — Concurrent Systems Programming with Go