DevTools

Go CLI

Go toolchain commands for building and managing Go projects.

29 commands
Windows MacOS Linux
#golang #build-tool

Module Management

Initialize a new module
go mod init example.com/myapp
Add missing and remove unused modules
go mod tidy
Download modules to local cache
go mod download
Copy dependencies into vendor directory
go mod vendor
Print the module dependency graph
go mod graph
Add or update a dependency
go get golang.org/x/tools@latest

Build & Run

Build all packages
go build ./...
Build with custom output name
go build -o myapp .
Compile and run a Go program
go run main.go
Run the package in current directory
go run .
go install example.com/cmd/tool@latest # Install a binary globally

Testing

Run all tests recursively
go test ./...
Run tests with verbose output
go test -v ./...
Run specific test by name
go test -run TestName ./pkg
Run tests with coverage report
go test -cover ./...
Run benchmarks
go test -bench=. ./...
Run tests with race detector
go test -race ./...

Formatting

Format all Go files in place
gofmt -w .
Show formatting diffs
gofmt -d .
Report suspicious constructs
go vet ./...
Check for variable shadowing
go vet -shadow ./...

Tools

Show documentation for a symbol
go doc fmt.Println
Print Go environment variable
go env GOPATH
Run go generate directives
go generate ./...
Print Go version
go version
List all module dependencies
go list -m all

Quick Commands

Compile all packages in the project
go build ./...
Run all tests in the project
go test ./...
Sync module dependencies with source code
go mod tidy