Go 1 cheatsheet

Go 1: Modules and dependencies

10 common Go 1 tasks.

Add a dependency

Add a module at its latest version to go.mod.

go get github.com/gin-gonic/gin@latest

Tidy go.mod

Add missing modules and remove unused ones. Run it after changing imports.

go mod tidy

Download all dependencies

Download modules to the module cache, as CI and Docker builds do.

go mod download

Update all dependencies

Upgrade the dependencies of your packages to their newest minor or patch versions.

go get -u ./...

See available updates

List modules that have newer versions.

go list -u -m all

Find out why a module is needed

Show the import chain that requires a module.

go mod why github.com/pkg/errors

Print the dependency graph

Print each module and the modules it requires.

go mod graph

Use a local copy of a module

Point a dependency at a folder on disk while you develop it.

go mod edit -replace example.com/lib=../lib

Vendor dependencies

Copy dependencies into a vendor folder for reproducible offline builds.

go mod vendor

Create a workspace

Work on several modules together without editing their go.mod files.

go work init ./app ./lib

Was this page helpful?