Tooling#

Go’s tooling is unusually consistent: most things you need ship with the go command itself.

Compiler / Runtime#

The go command compiles, links, runs, tests, and manages dependencies.

$ go version
$ go build ./...
$ go run ./cmd/app
$ go install example.com/tool@latest

Modules#

Go’s dependency management. go mod init creates the manifest; go get adds and updates dependencies; go mod tidy reconciles imports against the manifest; go list -m all lists every direct and transitive dependency. The module graph is the source of truth.

$ go mod init example.com/app
$ go get github.com/some/dep@v1.2.3
$ go mod tidy
$ go list -m all

Formatter#

  • gofmt, the standard formatter; runs on save in every editor.

  • goimports, gofmt plus automatic import management.

$ gofmt -w .
$ goimports -w .

Linters#

The lint stack. go vet is bundled and catches a curated set of bugs; staticcheck is the standard third-party linter with deeper analysis; golangci-lint aggregates many linters into one runner with sensible defaults. CI should run all three on every PR.

  • go vet, ships with the toolchain; catches a curated set of bugs.

  • staticcheck, the standard third-party linter.

  • golangci-lint, aggregator that runs many linters in parallel.

$ go vet ./...
$ staticcheck ./...
$ golangci-lint run

Testing#

The standard library’s testing package is the test framework. go test discovers and runs *_test.go files.

$ go test ./...
$ go test -run TestFoo -v ./pkg/...
$ go test -race ./...
$ go test -bench=. ./...
$ go test -coverprofile=cover.out ./... && go tool cover -html cover.out

Companion libraries.

Debugging#

The diagnostic toolkit. Delve is the standard interactive debugger and integrates with VS Code and JetBrains; go test -race exercises the race detector; runtime/pprof and net/http/pprof produce CPU, heap, goroutine, and block profiles for production debugging.

  • Delve, the standard Go debugger; integrates with VS Code and JetBrains.

  • go test -race, the race detector (also works with go run / go build).

  • runtime/pprof, net/http/pprof, CPU, memory, goroutine, block profiles.

Documentation#

  • go doc <pkg>, print docs for a package.

  • pkgsite, runs go.dev locally.

Doc comments live directly above the declaration; no special markup needed.

Editor Support#

  • gopls, the official Go LSP.

Most IDEs auto-install gopls, gofmt, and staticcheck on first open.

Cross-Compilation#

Set GOOS and GOARCH before go build:

$ GOOS=linux  GOARCH=amd64  go build -o app-linux  ./cmd/app
$ GOOS=darwin GOARCH=arm64  go build -o app-mac    ./cmd/app
$ GOOS=windows GOARCH=amd64 go build -o app.exe    ./cmd/app