Skip to Content
Skip to content
PROGRAMMING

Go Tutorials

Standalone Go tutorials covering concrete runtime traps and service patterns: slice backing-array aliasing, nil-map panics, typed-nil interfaces, context.Context timeouts, worker pools, go test -race data races, pprof allocations, and static binaries under 10 MB.

Each guide pairs a small runnable Go program with its exact compiler, test, or benchmark output so you can verify the behavior locally.

Go
Find and Fix Go Data Races With -race Level: Advanced

Trigger a real data race under go test -race, read the race detector output, and fix shared counters, maps, and slice writes using atomic, sync.Mutex, and disjoint indices.

Go
Benchmark Speed and Heap Allocations With go test -bench -benchmem Level: Advanced

Measure nanoseconds and heap allocations with testing.B and -benchmem, compare += vs strings.Builder, pre-size slices, and reuse buffers with sync.Pool.

Go
Embed Static Files and Build Versions Into a Go Binary Level: Advanced

Bundle static files with //go:embed and embed.FS, serve subdirectories cleanly with fs.Sub, and inject version strings with -ldflags -X or debug.ReadBuildInfo.

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.

Go
Run a Go Binary in FROM scratch With CA Certificates and Non-Root User Level: Advanced

Package a static Go binary in a FROM scratch Docker image with CA certificates for outbound HTTPS calls and a non-root numeric UID so the container runs safely in production.

Go
Find Edge-Case Panics in Go With go test -fuzz Level: Advanced

Write FuzzX(f *testing.F) targets and run go test -fuzz to discover edge-case panics and automatically save regression cases under testdata/fuzz.