Go Reference
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The reference material consulted while preparing these pages is listed in the section bibliography. |
This section is written against Go 1.27 (the current stable release is go1.27.2), checked on 2026-10-18. Go ships a
major release about every six months and supports the two newest ones, here Go 1.27 and Go 1.26; Go 1.28 is not
released yet (it is expected around February 2027), so nothing here depends on it. Features newer than the oldest
supported release are marked with the version that introduced them, for example WaitGroup.Go (1.25), b.Loop (1.24),
range over functions (1.23), per-iteration loop variables and the enhanced ServeMux (1.22), generics (1.18), and in
1.27 generic methods and encoding/json/v2. Every go.mod shown declares go 1.27, and every example was compiled,
vetted and run with go1.27.2.
What Go is
Go is a compiled, statically typed, garbage-collected language designed at Google by Robert Griesemer, Rob Pike and
Ken Thompson and released as open source in 2009. It aims at software that is easy to read, fast to build and simple to
deploy: a small language specification, a fast compiler that produces a single static binary, implicit interfaces and
composition instead of inheritance, errors as ordinary values, and first-class concurrency with goroutines, channels
and select. Around the language sits one official toolchain — the go command with its module system, gofmt,
go vet, go test with benchmarks and fuzzing, go doc and the profilers — and a large standard library that covers
HTTP, JSON, cryptography, templates and databases without third-party code. Go powers cloud infrastructure
(Docker, Kubernetes, Prometheus and Terraform are written in it), network services, command-line tools and, with
WebAssembly, code that runs in browsers and WASI hosts.
The shelf scenario
The examples across the section share one small, original domain: shelf, a Go module (example.com/shelf, go 1.27)
for a library catalogue. It is deliberately the same domain as the Rust
Reference, so you can compare the two languages on the same types.
-
The
catalogpackage holdsBook,Author,ISBN(a validated defined type with aStringmethod),LoanandLoanState(aniotaenumeration) types, aStoreinterface and an in-memory implementation guarded by a mutex. -
An
internal/package holds helpers that are not part of the public API. -
cmd/shelfis a command-line program that searches, lends and returns books and imports and exports JSON. -
cmd/shelfdis an HTTP service that exposes the catalogue as JSON withnet/http,log/sloganddatabase/sql. -
Tests, benchmarks, a fuzz test for ISBN parsing and a testable example grow alongside the code.
The pages build on each other, and the cheat sheet summarises them.
New here? Read in this order
-
Getting Started — install Go, the
gocommand, a first program -
Methods and Receivers and Interfaces — how Go does abstraction
-
Goroutines and the Scheduler, Channels and Select and Context — the concurrency model
Then pick topics as you need them, and keep the cheat sheet at hand. If you know an older tutorial, start with What’s New and Migrating Older Code.
What’s covered
Getting started
| Page | What it covers |
|---|---|
what Go is for, installing it, the go command, editors, Hello world, the Playground and the shelf module |
|
GoLand, VS Code, Neovim and gopls |
|
release cycle, support policy, the Go 1 promise, go and toolchain lines, GOTOOLCHAIN, GODEBUG |
|
source files, tokens, semicolon insertion, comments, program execution |
|
the design goals, what Go leaves out, and a map from other languages |
Core language
| Page | What it covers |
|---|---|
var, short declarations, zero values, typed and untyped constants, iota |
|
every predeclared type with size, range and zero value, conversions, literals |
|
arithmetic, comparison, logical and bit operators, precedence, order of evaluation |
|
if, the four for forms, range, switch, type switch, labels, goto |
|
parameters, results, variadics, closures, defer, panic and recover |
|
pointers, nil, new, copying, escape and value versus pointer design |
Composite types
| Page | What it covers |
|---|---|
arrays, the slice header, append and capacity, aliasing, the slices package |
|
map types, comma-ok, delete and clear, iteration order, sets, the maps package |
|
strings as bytes, runes, UTF-8, conversions, strings.Builder |
|
fields, literals, tags, comparison, embedding and promotion |
Abstraction
| Page | What it covers |
|---|---|
value and pointer receivers, method sets, method values and expressions |
|
implicit satisfaction, embedding, nil interfaces, assertions, type switches, any |
|
encapsulation, constructors, functional options and polymorphism without classes |
|
type parameters, constraints, inference, generic types and (Go 1.27) generic methods |
|
iter.Seq and Seq2, range over functions, iter.Pull, slices and maps helpers |
|
errors as values, wrapping, Is, As, AsType, Join, custom and sentinel errors |
Concurrency
| Page | What it covers |
|---|---|
the go statement, lifetimes, WaitGroup.Go, the GMP scheduler, GOMAXPROCS |
|
unbuffered and buffered channels, close, the axioms table, select |
|
pipelines, fan-out and fan-in, worker pools, semaphores, errgroup |
|
cancellation, deadlines, values, AfterFunc and propagation through a call tree |
|
Mutex, RWMutex, Once, Pool, Map, Cond and typed atomics |
|
happens-before, synchronization points, the race detector |
Packages, modules and tooling
| Page | What it covers |
|---|---|
packages, import forms, visibility, init order, internal |
|
go.mod directives, versions, MVS, go.sum, proxies, vendoring, tool directives |
|
go.work, version numbers, publishing, retraction, major versions |
|
go build and friends, flags, ldflags, build constraints, GOOS and GOARCH |
|
go:generate, go:embed, go:build, go:debug, go:fix inline and other directives |
|
go test, table tests, subtests, helpers, examples, coverage, t.Context |
|
b.Loop benchmarks, benchstat, native fuzzing, testing/synctest |
|
gofmt, goimports, go vet, go fix modernizers, staticcheck, golangci-lint |
|
doc comment syntax, go doc, pkgsite, examples, deprecation notices |
Standard library
| Page | What it covers |
|---|---|
fmt verbs, strings, strconv, bytes, regexp, text/scanner |
|
text/template and html/template actions, pipelines and escaping |
|
io interfaces, bufio, os, io/fs, os.Root, embed and filepath |
|
Duration, Time, zones, layouts, Timer and Ticker semantics |
|
encoding/json v1, struct tags, streaming, and encoding/json/v2 with jsontext |
|
Logger, Handler, levels, attributes, groups and custom handlers |
|
Client, Transport, ServeMux patterns, middleware, timeouts, CrossOriginProtection |
|
the connection pool, queries, transactions, null handling and context |
|
os.Args, flag, exit codes, signals, os/exec and process boundaries |
|
slices, maps, cmp, sort, container, math, big, unique and friends |
|
crypto/rand, hashing, HMAC, AEAD, TLS, post-quantum and FIPS 140-3 |
Runtime, advanced topics and interop
| Page | What it covers |
|---|---|
the three laws, Type, Kind, Value, struct tags and their costs |
|
unsafe.Pointer rules, Sizeof, alignment, struct padding, syscall |
|
escape analysis, the allocator, the GC cycle, GOGC and GOMEMLIMIT |
|
finalizers, AddCleanup, weak pointers and unique |
|
pprof, trace, flight recorder, goroutine leak profiles, runtime/metrics |
|
the measure-change loop, inlining, escape analysis and profile-guided optimization |
|
import "C", type conversion, pointer-passing rules, calling Go from C |
|
GOOS=js and GOOS=wasip1, wasmexport, hosts and limits |
Practice and evolution
| Page | What it covers |
|---|---|
Effective Go in 2026, Code Review Comments, Google and Uber style guides |
|
the classic pitfalls with causes, symptoms and fixes |
|
Go 1.18 to 1.27 release by release, and migrating older code |
Quick reference
Cheat Sheet — one A4 page, downloadable as a PDF.
Related material on this site
-
The Rust Reference uses the same shelf domain, which makes it easy to compare ownership and traits with Go’s garbage collection and interfaces.
-
The C Reference explains pointers, memory layout and threads at the level that the pointer,
unsafe, cgo and memory-model pages build on. -
Command-line applications in Go (Cobra, Bubble Tea, testscript, GoReleaser): CLI Frameworks in Go and Rust. A dedicated CLI Apps section is planned (issue #236), as is a comparison of programming languages (issue #196).
-
Operators and controllers written in Go: Custom Resources and Operators and Helm; metrics from Go services: Instrumenting Applications.
-
Containers, databases and authentication used by
shelfd: Docker, SQL, Redis, MongoDB, OAuth and CORS. -
Starting a service in Go next to other stacks: Starting a New Project.
The section draws on the official documentation first, and on two books for concept coverage.
Bibliography
Books
-
Jon Bodner, Learning Go: An Idiomatic Approach to Real-World Go Programming, 1st edition. O’Reilly Media, 2021 (March). ISBN 978-1-492-07721-3 (print), 978-1-492-07720-6 (eBook). Publisher page; companion code. A 2nd edition (O’Reilly, January 2024, ISBN 978-1-098-13929-2, publisher page) exists; it is a newer edition that was not consulted.
-
Vladimir Vivien, Learning Go Programming, 1st edition (technical reviewers Quintessence Anx, Parth Desai, Abhishek Kumar and Chris Schaefer). Packt Publishing, 2016 (October). ISBN 978-1-78439-543-8. Publisher page; companion code and Packt repository. Its fundamentals are still useful; its GOPATH-era tooling chapters are obsolete.
The books are consulted references, not the primary source: no text, listing or figure was taken from them, and every example was written against the current official documentation. On any discrepancy, and wherever a book is silent on a later feature, the official documentation wins; where a book shows an outdated form, the pages say so in prose (collected on What’s New and Migrating Older Code).
Official Go documentation and resources
-
go.dev and the documentation index
-
The Go Programming Language Specification and The Go Memory Model
-
Effective Go (it predates generics and modules; the pages say where it is dated)
-
The tutorials: getting started, create a module, call your code from another module, workspaces, generics, fuzzing, database access, govulncheck, JSON and a web service with Gin
-
Go Modules Reference, the go.mod reference and the module guides: managing dependencies, publishing, release workflow, version numbers, organizing a module and major version updates
-
The go command and the command documentation: gofmt, vet, fix, cgo, compile, link, pprof, trace, cover, doc and test2json
-
Go Toolchains, Go, Backwards Compatibility, and GODEBUG, Go 1 and the Future of Go Programs, Download and install and Deprecation of go get for installing executables
-
Release history and notes: release history, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.20, 1.21, 1.22, 1.23, 1.24, 1.25, 1.26, 1.27 and the release cycle
-
The standard library: pkg.go.dev/std, with every package page used cited on the page that covers it
-
Diagnostics, A Guide to the Go Garbage Collector, Profile-guided optimization, Data Race Detector, Coverage profiling support for integration tests, Go Telemetry, Debugging Go Code with GDB and A Quick Guide to Go’s Assembler
-
The Go Wiki: Code Review Comments, Table-Driven Tests, Common Mistakes, Slice Tricks, WebAssembly, Minimum Requirements, cgo, Mutex or Channel, Rate Limiting, Bounding Resource Use, SQL Drivers, PGO Tools, Compiler Optimizations, Loopvar Experiment and Rangefunc Experiment
-
Security: Go security, best practices, security policy, fuzzing, vulnerability management, the vulnerability database, govulncheck and FIPS 140-3
-
encoding/json/v2 Migration Guide and Accessing relational databases
-
The Go Playground, pkg.go.dev, the module mirror proxy.golang.org and the checksum database sum.golang.org
-
Design documents and proposals: golang/proposal, for instance the Type Parameters Proposal, and the non-cooperative preemption design
Go blog posts
The Go blog posts used by the pages, each cited on the page that derives from it: alias names, allocation optimizations, archsimd, cgo, chacha8rand, cleanups and weak, codelab share, comparable, compat, concurrency timeouts, constants, container aware gomaxprocs, context, context and structs, coretypes, cover, deadcode, defer panic and recover, error handling and go, error syntax, errors are values, examples, execution traces 2024, fips140, flight recorder, generate, generic interfaces, generic methods, generic slice functions, get familiar with workspaces, go1.13 errors, go1.21, go15gc, gob, gofix, gofmt, goroutine leak profiles, greenteagc, inliner, integration test coverage, intro generics, io2013 talk concurrency, ismmkeynote, json, jsonv2 exp, laws of reflection, loopvar preview, maps, module compatibility, module mirror launch, normalization, organizing go code, osroot, package names, path security, pgo, pgo preview, pipelines, playground, pprof, profiling go programs, publishing go modules, race detector, randv2, range functions, rebuild, routing enhancements, simd experiment, size specialized allocations, slices, slices intro, slog, strings, subtests, supply chain, swisstable, synctest, testing b loop, testing time, toolchain, type inference, unique, using go modules, v2 go modules, wasi, wasmexport, waza talk, when generics, why generics.
golang.org/x repositories
The golang.org/x repositories are maintained by the Go team but sit outside the standard library and have looser
compatibility guarantees; they are labelled as such where used.
Community references
These are not official; the pages label them as community material.
-
go-cmp and testscript
-
TinyGo, wazero, Wasmtime and Node.js WASI for the WebAssembly page
-
Helm chart template guide and kubectl get for the template examples
-
The
golang-standards/project-layoutrepository is not an official standard; the official guidance is Organizing a Go module
Specifications and standards
-
RFC 9562 (UUIDs)
-
IEEE 754 floating point, as described by the Go specification’s numeric types
-
WebAssembly and WASI (Preview 1)