Go CLI Tools and Generate

go tool, go generate, code generation, formatting helpers, analysis tools, and practical developer automation with the Go CLI.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

go generate

go generate commands and patterns for the Go command.

Run generators

Run go:generate directives in the current module.

bashANYgogenerate
bash
go generate ./...

Run go:generate directives in the current module. Useful in Go CLI workflows.

Run matching generators

Only run generators whose command matches a regexp.

bashANYgogenerate
bash
go generate -run "stringer|mockgen" ./...

Only run generators whose command matches a regexp. Useful in Go CLI workflows.

Print commands while generating

Echo each generate command before running it.

bashANYgogenerate
bash
go generate -x ./...

Echo each generate command before running it. Useful in Go CLI workflows.

go tool

go tool commands and patterns for the Go command.

Run tool help

Show help for a specific Go tool.

bashANYgotool
bash
go tool cover -help

Show help for a specific Go tool. Useful in Go CLI workflows.

Analyze profiles

Open a CPU or memory profile with pprof.

bashANYgopprofprofiles
bash
go tool pprof cpu.prof

Open a CPU or memory profile with pprof. Useful in Go CLI workflows.

Inspect execution trace

Open an execution trace for visualization.

bashANYgotrace
bash
go tool trace trace.out

Open an execution trace for visualization. Useful in Go CLI workflows.

Inspect assembler help

Show available assembler flags.

bashANYgotool
bash
go tool asm -help

Show available assembler flags. Useful in Go CLI workflows.

Formatting and source transforms

Formatting and source transforms commands and patterns for the Go command.

Format file in place

Format a file and write changes.

bashANYgogofmt
bash
gofmt -w main.go

Format a file and write changes. Useful in Go CLI workflows.

Preview formatting diff

Print the file if formatting would change it.

bashANYgogofmt
bash
gofmt -d .

Print the file if formatting would change it. Useful in Go CLI workflows.

Apply Go source fixes

Update packages using automated code fixers.

bashANYgofix
bash
go fix ./...

Update packages using automated code fixers. Useful in Go CLI workflows.

Analysis and inspection

Analysis and inspection commands and patterns for the Go command.

Compile tests only

Build tests without running them.

bashANYgotestcompile
bash
go test -run=^$ ./...

Build tests without running them. Useful in Go CLI workflows.

List transitive deps

List all packages including dependencies.

bashANYgolistdeps
bash
go list -deps ./...

List all packages including dependencies. Useful in Go CLI workflows.

Custom package fields

Print custom package metadata fields via template.

bashANYgolisttemplate
bash
go list -f "{{.ImportPath}} {{.Dir}}" ./...

Print custom package metadata fields via template. Useful in Go CLI workflows.

Recommended next

No recommendations yet.