Go Language Cheat Sheet
Go Language Cheat Sheet
Of the many things the go executable can do, most people know only go run and go build. And, of the many
packages in the standard Go library, most people know only the fmt package. This cheat sheet will list many
uses of the go executable and the most important packages in the Go standard library.
The go command
The go command can do many things, including:
• go bug: creates a bug report • go list: lists packages or modules; executing go list
• go build: compiles the packages named by the import without any command line arguments returns the name
paths, along with their dependencies, without installing of the current directory’s import path
the results • go mod: permits working with modules (go mod first
• go clean: removes object files from package source appeared in Go 1.11)
directories • go run: compiles and runs a Go package with a main()
• go doc: provides Go’s documentation function
• go env: returns information about the Go environment • go test: enables users to execute test packages and see
their results
• go fix: updates packages to use new APIs
• go tool: runs a specific go tool, including: addr2line, api,
• go fmt: reformats Go package files; can be also called asm, buildid, cgo, compile, cover, dist, doc, fix, link,
as gofmt nm, objdump, pack, pprof, test2json, trace, and vet
• go install: compiles and installs the packages given as • go version: returns the current version of Go
command line arguments
• go help: provides help about a topic or a command
Go packages
The Go standard library is very rich and includes many handy packages including:
• bufio: implements buffered I/O •m
ath/rand: contains functions for producing pseudo-
• bytes: contains functions for working with byte slices random number generators
• compress: contains Go packages (bzip2, flate, gzip, •n
et: contains portable functions for network I/O
lzw, and zlib) for writing and reading compressed files •n
et/http: contains functions for creating web servers
• errors: contains functions for working with errors and and clients
the error data type •n
et/http/pprof: offers a high-level package for profiling
• flag: does the dirty work of parsing command line web applications written in Go (and supplements
arguments and options the low-level runtime/pprof function available in the
standard Go package)
• fmt: contains functions for implementing formatted I/O,
similar to the printf(3) and scanf(3) C functions •n
et/url: contains functions for parsing URLs