Skip to Content
Skip to content
Tutorials

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.

Go
Run Concurrent Tasks Safely With sync.WaitGroup and wg.Go Level: Intermediate

Wait for parallel goroutines using sync.WaitGroup and wg.Go, collect results into disjoint slice indices without locks, and verify with go test -race.

Go
Stop Goroutine Leaks With select, close(ch), and ctx.Done() Level: Intermediate

Prevent blocked producer and consumer goroutines from leaking forever by closing channels on the sender side and selecting on ctx.Done().

Go
Handle sql.ErrNoRows and Close *sql.Rows in database/sql Level: Intermediate

Check sql.ErrNoRows cleanly with errors.Is, close *sql.Rows with defer rows.Close(), check rows.Err(), and use bound parameters.

Go
Capture HTTP Status Codes in Go Middleware With a ResponseWriter Wrapper Level: Intermediate

Write composable func(http.Handler) http.Handler middleware, embed http.ResponseWriter to record status codes, and return early on auth failures.

Go
Shut Down a Go HTTP Server Gracefully With signal.NotifyContext Level: Intermediate

Handle SIGINT and SIGTERM with signal.NotifyContext, drain active requests with server.Shutdown(ctx), and test shutdown under -race.

Go
Bound Concurrency in Go With a Fixed Worker Pool Level: Advanced

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.

Go
Choose Between sync.Mutex, sync.RWMutex, and sync/atomic Level: Advanced

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.

Go
Reuse Buffers Without Corrupting Data Using sync.Pool Level: Advanced

Cut per-request allocations with sync.Pool without leaking stale bytes across requests or holding onto oversized buffers forever.

Go
Find CPU and Heap Hotspots in Go With pprof Level: Advanced

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.

Go
Catch Goroutine Leaks and Hanging Tests With t.Cleanup and go test -timeout Level: Advanced

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.

Go
Retry Transient Failures in Go With Exponential Backoff and Jitter Level: Advanced

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.

Go
Recover From Panics and Cap Request Bodies in Go HTTP Middleware Level: Advanced

Keep one handler panic or one oversized JSON payload from crashing a Go API server using recover middleware and http.MaxBytesReader.