Go 1 cheatsheet

Go 1: Quality and release builds

8 common Go 1 tasks.

Format the code

Rewrite files in the standard Go style.

go fmt ./...

Find likely mistakes

Report suspicious constructs such as wrong Printf formats.

go vet ./...

Read documentation

Show the documentation for a package or symbol in the terminal.

go doc net/http.Client

Run code generators

Run //go:generate directives found in the source.

go generate ./...

Cross-compile for Linux

Build for another operating system and architecture.

GOOS=linux GOARCH=amd64 go build -o myapp-linux .

Build a small static binary

Disable cgo and strip debug information for a compact, portable binary.

CGO_ENABLED=0 go build -ldflags="-s -w" -o myapp .

Set a version at build time

Set a string variable in package main from the command line.

go build -ldflags "-X main.version=1.2.3" -o myapp .

Clear the build cache

Delete cached build results, for example to rule out stale artifacts.

go clean -cache

Was this page helpful?