2. Toolchain, modules, workspaces
One-liner. go.mod is a contract about language version and dependencies; the toolchain line decides who compiles it.
Memorize
go.mod: module path,godirective (language semantics + minimum toolchain), requirements.go.sumpins content hashes; the checksum database (sum.golang.org) detects tampering.- Semantic import versioning: major ≥ 2 requires
/v2in the module path. toolchaindirective (1.21): if the installed toolchain is older, Go downloads the required one.GOTOOLCHAIN=localpins to the installed version (air-gapped CI, reproducible builds).- Workspaces (
go.work): build several modules together locally; don't commit for libraries. tooldirective (1.24):go get -toolrecords dev tools ingo.mod, replacingtools.go.go mod tidyis not optional hygiene — it prunes the graph thatgo.sumcovers.
Trap. Committing go.work — it silently overrides dependency resolution for everyone who clones the repo. Do this. Bump the go directive deliberately, in its own commit, after CI agrees.
Check
A repo declares toolchain go1.24.1; CI has Go 1.23 installed. What happens by default?
Why
Since 1.21 the toolchain line triggers an automatic download unless GOTOOLCHAIN=local forbids it.