`time.NewTicker(d)` fires on a channel every `d` interval. Combine with select + a done channel for a clean way to run periodic work that can be cancelled.
Attach data to a context that flows down through your call chain — request IDs, authenticated user, trace spans. Use a private key type to avoid collisions across packages.
A table of test cases looped through `t.Run` gives every case its own name in the output, makes adding new cases trivial, and lets you run individual cases with `-run TestX/case_name`.
Use pointers when you want to mutate the callee's value, share a large struct without copying, or distinguish "no value" via nil. Go has no pointer arithmetic — much safer than C.
Stdlib templating with `{{.Field}}` placeholders, range loops, if/else, and function pipelines. Safe alternative for non-HTML text (e.g. emails, config files).
`golang.org/x/time/rate` provides a battle-tested token-bucket limiter. Use to enforce "N requests per second with bursts up to B" — for per-IP throttling, external API rate limits, etc.
A pipeline is a chain of stages connected by channels — each stage runs in its own goroutine. Classic Go pattern for streaming transformations with backpressure built in.
Channels are typed pipes between goroutines. Unbuffered = synchronous handoff; buffered = up to N values queued. Close a channel to signal "no more values" — receivers see ok=false.
`json.RawMessage` is a `[]byte` that survives a decode pass. Use it for envelope-style JSON where one field's type depends on another (e.g. `{"type":"X","payload":{...}}`).
Go Struct Embedding (Composition over Inheritance)
Go has no inheritance. Embed a type to "promote" its fields and methods as if they were on the outer type. Same effect as inheritance for most purposes, but explicit.
`os.Getenv` returns "" when unset — easy to miss. Wrap it with a typed helper that supplies defaults and parses numerics. Saves boilerplate at every config-read site.
`encoding/csv` parses RFC 4180 CSVs. Read row-by-row with `Read()` or all at once with `ReadAll()`. Same for writing — flush with `Writer.Flush()` before closing.
`http.DefaultClient` has no timeout — a hung server can hang your whole program forever. ALWAYS use a custom client with an explicit timeout for outbound requests.
Middleware in Go is `func(http.Handler) http.Handler`. Wrap a handler with logging, auth, recovery, CORS, or rate limiting — chain them together for a real middleware stack.