Commands

Updated: November 24, 2025

CLI commands for Golang.

Table of Contents

Build

Compiles the packages and produces an executable.

go build  // produces a single executable file named after the project

Fix

Rewrites programs to use newer APIs.

go fix  // update code to use newer APIs

Format

Automatically formats Go source code.

go fmt -w main.go  // format source code and write results to file

Generate

Generates code by running commands specified in //go:generate comments.

go generate ./...  // run generate commands in current directory and subdirectories

Get

Downloads and installs packages and dependencies.

go get <package>  // import dependency packages

Imports

Manages import statements in Go files.

goimports -w main.go  // detects missing packages and updates imports

Run

Compiles and runs the program from source code without generating an output file.

go run  // build and run program straight from source code

Test

Runs tests in the package.

go test  // run tests in current package
go test ./...  // run tests in all packages
go test -v  // verbose output

Vet

Reports suspicious constructs in Go code.

go vet  // check for common errors
go vet ./...  // check all packages