Tutorials
Practical tutorials for the work we actually do. Pick one, read it in order, and apply it.
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.
Wait for parallel goroutines using sync.WaitGroup and wg.Go, collect results into disjoint slice indices without locks, and verify with go test -race.
Prevent blocked producer and consumer goroutines from leaking forever by closing channels on the sender side and selecting on ctx.Done().
Check sql.ErrNoRows cleanly with errors.Is, close *sql.Rows with defer rows.Close(), check rows.Err(), and use bound parameters.
Write composable func(http.Handler) http.Handler middleware, embed http.ResponseWriter to record status codes, and return early on auth failures.