Go Modules
Understand go.mod and go.sum, add and tidy dependencies, work with versions and major version paths, and use replace.
Modules are how Go tracks versions of the code you depend on. This section covers the files, the commands and the version rules.
go.mod and go.sum
go mod init example.com/shop creates go.mod. go.sum stores checksums. Commit both, and you no longer need GOPATH for your own code.
Adding and Tidying Dependencies
go mod tidy
go get github.com/google/uuid@v1.6.0
no required module provides package:
This error means an import has no matching require line. Run go mod tidy.
Versions and Upgrades
Semantic versioning, /v2 import paths for major versions, pseudo-versions and minimal version selection.
The replace Directive
Point a dependency at a local folder or a fork. It only applies to your own module.
Summary
Let go mod tidy maintain your module files, pick versions with go get, and use replace only briefly.
go.mod and go.sum Explained
What a Go module is, what each line in go.mod means, what go.sum is for, and why you no longer need GOPATH.
Adding and Tidying Dependencies with go get and go mod tidy
How to add, update and remove Go dependencies with go get and go mod tidy, and what the no required module provides package error means.
Go Module Versions and Upgrades
How semantic versioning works for Go modules, why v2 and later need a new import path, pseudo-versions, minimal version selection and safe upgrades.
The replace Directive in go.mod
Use replace in go.mod to point a dependency at a local folder or a fork, when to use it, and why it does not apply to modules that depend on yours.