Christian Giacomi

Go mod cheat sheet

Posted — Mar 15, 2019

This is a simple cheat sheet for go modules, listing the main commands.

Initialization

Create a new module, with automatic module path resolution.

$ go mod init

go: creating new go.mod

Create a new module, with explicit module path.

$ go mod init github.com/my/repo

go: creating new go.mod: module github.com/my/repo

Clean up

Prune any no-longer-needed dependencies and add any dependencies needed for other combinations of OS and architectures.

$ go mod tidy

Vendoring

Create a vendor directory with the exact version of the dependencies to use during build.

$ go mod vendor

Why

Why a module or package is being kept.

go mod why module

Dependencies

Display the dependencies of your module.

go mod graph
If this post was helpful tweet it or share it.