Programming Tutorials
Standalone programming tutorials for solving one specific problem at a time. Each guide starts with the exact error message, failing behavior, or design constraint, gives you a minimal reproducible script or query, and walks through the fix with real output.
Pick a language below or filter by topic and difficulty when you need a quick, practical reference you can test locally and apply right away.
Wait for parallel goroutines using sync.WaitGroup and wg.Go, collect results into disjoint slice indices without locks, and verify with go test -race.
Prevent blocked producer and consumer goroutines from leaking forever by closing channels on the sender side and selecting on ctx.Done().
Check sql.ErrNoRows cleanly with errors.Is, close *sql.Rows with defer rows.Close(), check rows.Err(), and use bound parameters.
Write composable func(http.Handler) http.Handler middleware, embed http.ResponseWriter to record status codes, and return early on auth failures.
Handle SIGINT and SIGTERM with signal.NotifyContext, drain active requests with server.Shutdown(ctx), and test shutdown under -race.
Stop spawning an unbounded goroutine per job and build a fixed-size worker pool in Go with bounded channels, context cancellation, and predictable memory usage.
Compare sync.Mutex, sync.RWMutex, and sync/atomic on real read-heavy and write-heavy Go benchmarks, and see when RWMutex slows down under contention.
Cut per-request allocations with sync.Pool without leaking stale bytes across requests or holding onto oversized buffers forever.
Capture CPU and heap profiles from a Go test or net/http/pprof endpoint, read flat vs cum in go tool pprof -top, and verify that a fix actually reduced allocations.
Detect leaked goroutines and deadlocked channels in Go tests using runtime.NumGoroutine, t.Cleanup, and go test -timeout instead of waiting for a 10-minute CI hang.
Build a Go retry helper that only retries 429 and 5xx errors, adds full jitter to avoid thundering herds, and respects context.Context cancellation between attempts.
Keep one handler panic or one oversized JSON payload from crashing a Go API server using recover middleware and http.MaxBytesReader.