Go mod cheat sheet

Go mod cheat sheet

A simple cheat sheet when using Go modules

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

Initialization

Create a new module, with automatic module path resolution.

1
2
3
$ go mod init

go: creating new go.mod

Create a new module, with explicit module path.

1
2
3
$ 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.

1
$ go mod tidy

Vendoring

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

1
$ go mod vendor

Why

Why a module or package is being kept.

1
go mod why module

Dependencies

Display the dependencies of your module.

1
go mod graph
This post is licensed under CC BY 4.0.