Idiomatic Go
Write production Go — the standard library plus generics, reflection, and advanced techniques.
fmt — Formatted I/O
The `fmt` package implements formatted I/O. `fmt.Printf` writes formatted text t...
errors — Error Handling Utilities
The `errors` package provides `errors.New` (create a sentinel error), `errors.Is...
io — I/O Primitives
The `io` package defines the fundamental I/O interfaces: `io.Reader` (`Read([]by...
os — Operating System Interface
The `os` package provides OS-level operations: file I/O, environment variables, ...
net/http — HTTP Client and Server
`net/http` is a production-grade HTTP/1.1 and HTTP/2 library in the standard lib...
encoding/json — JSON Marshal/Unmarshal
`encoding/json` serializes Go values to JSON (`json.Marshal`) and deserializes J...
bufio — Buffered I/O
`bufio.Scanner` reads input line-by-line (or by custom split functions). `bufio....
log/slog — Structured Logging (Go 1.21+)
`log/slog`, added in Go 1.21, provides structured logging with key-value pairs. ...
testing — Unit Tests and Benchmarks
Go's built-in testing package requires no third-party dependencies. Test files e...
strings and strconv — String Operations
The `strings` package provides string manipulation: `strings.Contains`, `strings...
time — Time and Duration
The `time` package represents moments (`time.Time`) and durations (`time.Duratio...
sort and slices — Sorting
The `sort` package sorts slices and user-defined collections. `sort.Ints`, `sort...
regexp — Regular Expressions
The `regexp` package implements RE2-syntax regular expressions — a syntax with n...
math and math/rand — Numbers
The `math` package provides floating-point constants (`math.Pi`, `math.MaxInt64`...
flag — Command-Line Flags
The `flag` package parses command-line arguments into typed values. `flag.String...
path/filepath — File Paths
The `path/filepath` package manipulates file paths using the operating system's ...
Generics (Type Parameters)
Generics, introduced in Go 1.18, allow functions and types to be parameterized o...
Interface Composition
Go interfaces can embed other interfaces, building larger contracts from smaller...
Build Tags and Conditional Compilation
Build tags (also called build constraints) control which files are included in a...
unsafe Package
The `unsafe` package bypasses Go's type system and memory safety guarantees. `un...
CGo — Calling C from Go
CGo lets Go packages call C code and be called from C. Import `"C"` (a pseudo-pa...
Profile-Guided Optimization (PGO)
Introduced in Go 1.20 and enabled by default in 1.21, PGO optimizes compiled cod...
go:generate — Code Generation
`//go:generate command args` is a directive that `go generate` executes. It runs...
The Go Memory Model
The Go Memory Model specifies when a write by one goroutine is guaranteed to be ...
Escape Analysis
Escape analysis is a compile-time pass that decides whether a value lives on the...