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
Why a Typed Nil Pointer Is Not == nil in Go Interfaces Level: Intermediate

Reproduce Go's typed-nil interface trap with custom errors and io.Writer, see why w == nil returns false, and fix return paths cleanly.

Go
Add Context Deadlines to Outbound HTTP Calls in Go Level: Intermediate

Replace http.Get with http.NewRequestWithContext, combine Client.Timeout with per-call context.WithTimeout, and detect DeadlineExceeded cleanly.

Go
Replace fmt.Println With Structured JSON Logging in Go (log/slog) Level: Intermediate

Switch from fmt.Println to log/slog JSON logs, attach request-scoped attributes with With, redact secrets using LogValuer, and change log levels at runtime.

Go
Stream Large Files and HTTP Bodies With bufio.Scanner and io.LimitReader Level: Intermediate

Read large text streams line by line with bufio.Scanner, copy streams in bounded memory with io.Copy, and cap untrusted HTTP bodies with io.LimitReader.

Go
Cancel Slow Work With context.WithTimeout and r.Context() Level: Intermediate

Propagate cancellation signals and deadlines with context.WithTimeout, pair every context with defer cancel(), and respect r.Context() in HTTP handlers.

Go
Set ReadHeaderTimeout and Keep-Alive Timeouts on http.Server Level: Intermediate

Replace http.ListenAndServe with an explicit http.Server configured with ReadHeaderTimeout, ReadTimeout, WriteTimeout, and IdleTimeout.

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
Write Generic Functions in Go With comparable, cmp, slices, and maps Level: Intermediate

Use type parameters with comparable and cmp.Ordered alongside Go's standard slices and maps packages. After this, you eliminate duplicate helpers without losing type safety.