Go Cheat Sheet
|
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. |
A single-page, colour-coded summary of the Go language and its toolchain, written against Go 1.27 (go1.27.2; checked
2026-10-18) — the go command map and a go.mod skeleton with toolchain, tool, godebug and ignore, packages,
imports and initialization order, the table of basic types with zero values, literals and constants with iota,
declarations and operators, control flow with every for form, range over integers and functions and the Go 1.22
loop-variable rule, functions with defer, panic and recover, slices, maps, strings and the builtins, structs,
embedding and tags, methods with the method-set table, interfaces and the nil-interface pitfall, generics (including Go
1.27 generic methods) and iterators, errors with %w, Is, As, AsType and Join, goroutines, the channel axioms
table, select, context, sync and atomics, testing with b.Loop, fuzzing and testing/synctest, standard-library
one-liners, build constraints, directives and cross-compilation, diagnostics with pprof and PGO, reflection, unsafe,
cgo and WebAssembly, and a strip of what changed since older tutorials — handy for quick memorization or as a
downloadable PDF desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Start here — Go Reference.
Getting started — Getting Started, Toolchain Versions and Compatibility, Program Structure and Lexical Elements and Design Philosophy and Coming from Other Languages.
Core language — Variables, Constants and iota, Types and Values, Operators and Expressions, Control Flow, Functions, Closures and Defer and Pointers and Value Semantics.
Composite types — Arrays and Slices, Maps, Strings, Runes and UTF-8 and Structs and Embedding.
Abstraction — Methods and Receivers, Interfaces, Composition and Object-Oriented Design, Generics, Iterators and Range-over-Func and Error Handling.
Concurrency — Goroutines and the Scheduler, Channels and Select, Concurrency Patterns, Context, Sync and Atomics and Memory Model and Data Races.
Packages, modules and tooling — Packages, Imports and Initialization, Modules and Dependency Management, Workspaces, Versioning and Publishing, The go Command, Builds and Cross-Compilation, Directives, Code Generation and Embedding, Testing, Benchmarks, Fuzzing and synctest, Formatting, vet, fix and Static Analysis and Documentation and Doc Comments.
Standard library — fmt, Strings and Text Processing, Text and HTML Templates, I/O, Files and the Filesystem, Time and Timers, encoding/json, Structured Logging with slog, net/http Clients and Servers, database/sql, Command-Line Programs, Collections and Utility Packages and Crypto and Security.
Runtime, advanced topics and interop — Reflection, unsafe and Low-Level Programming, Memory Management and Garbage Collection, Cleanups, Weak Pointers and Interning, Profiling, Tracing and Diagnostics, Performance and PGO, cgo and C Interoperability and WebAssembly and WASI.
Practice and evolution — Idioms, Style and Code Review, Common Mistakes and Gotchas and What’s New and Migrating Older Code.
References
The PDF summarizes the official documentation; each source is cited in full on the page listed above that covers it, and in the section bibliography.