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
Run generators
go generate ./...

# Run go:generate directives in the current module.

Run matching generators
go generate -run "stringer|mockgen" ./...

# Only run generators whose command matches a regexp.

Print commands while generating
go generate -x ./...

# Echo each generate command before running it.

## go tool
Run tool help
go tool cover -help

# Show help for a specific Go tool.

Analyze profiles
go tool pprof cpu.prof

# Open a CPU or memory profile with pprof.

Inspect execution trace
go tool trace trace.out

# Open an execution trace for visualization.

Inspect assembler help
go tool asm -help

# Show available assembler flags.

## Formatting and source transforms
Format file in place
gofmt -w main.go

# Format a file and write changes.

Preview formatting diff
gofmt -d .

# Print the file if formatting would change it.

Apply Go source fixes
go fix ./...

# Update packages using automated code fixers.

## Analysis and inspection
Compile tests only
go test -run=^$ ./...

# Build tests without running them.

List transitive deps
go list -deps ./...

# List all packages including dependencies.

Custom package fields
go list -f "{{.ImportPath}} {{.Dir}}" ./...

# Print custom package metadata fields via template.

Recommended next

No recommendations yet.