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.
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.
Reproduce Go's typed-nil interface trap with custom errors and io.Writer, see why w == nil returns false, and fix return paths cleanly.
Replace http.Get with http.NewRequestWithContext, combine Client.Timeout with per-call context.WithTimeout, and detect DeadlineExceeded cleanly.
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.
Verify your Go installation with go version and go env, initialize a module with go mod init, and fix go.mod not found errors.
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.
Reproduce lost struct mutations with value receivers, switch to pointer receivers cleanly, and keep receiver types consistent across a struct.
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.
Structure Go unit tests as a slice of cases, run named subtests with t.Run, and choose between t.Fatalf and t.Errorf.
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.
Propagate cancellation signals and deadlines with context.WithTimeout, pair every context with defer cancel(), and respect r.Context() in HTTP handlers.
Replace http.ListenAndServe with an explicit http.Server configured with ReadHeaderTimeout, ReadTimeout, WriteTimeout, and IdleTimeout.