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
Strings, Bytes, and Runes in Go: Why len() Counts Bytes Level: Beginner

See why len() counts UTF-8 bytes instead of characters, iterate safely over runes with range, and slice UTF-8 text without splitting multi-byte characters.

Go
Value vs. Pointer Receivers in Go: Why Method Changes Disappear Level: Beginner

Reproduce lost struct mutations with value receivers, switch to pointer receivers cleanly, and keep receiver types consistent across a struct.

Go
Wrap and Check Errors in Go With fmt.Errorf("%w") and errors.Is Level: Beginner

Add context to Go errors using fmt.Errorf("%w"), inspect wrapped chains with errors.Is and errors.As, and avoid breaking checks with == or %v.

Go
Write Table-Driven Unit Tests in Go With testing.T and t.Run Level: Beginner

Structure Go unit tests as a slice of cases, run named subtests with t.Run, and choose between t.Fatalf and t.Errorf.

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.