Table of Contents
- Examples — Month 6 (Production, Observability & Capstone)
- Week 1 — logging, metrics, tracing, health
- Week 2 — packaging, CI, config, shutdown
- Week 3 — profiling, allocations, optimization, rate limiting
- Week 4 — capstone architecture
Examples — Month 6 (Production, Observability & Capstone)¶
Standard-library-only programs that teach this month's observability concepts.
The real production stack uses third-party libraries (prometheus/client_golang,
go.opentelemetry.io/otel), but the concepts — structured records, trace
propagation, probe semantics, request correlation — are reproducible with the
stdlib, so these compile and run with nothing installed. Where a topic genuinely
needs a third-party SDK (Prometheus client, OTel exporter), the day note shows
the real API as a snippet instead.
Week 1 — logging, metrics, tracing, health¶
| Topic | Run | Teaches | Day |
|---|---|---|---|
slog |
go run ./examples/month-06/slog |
structured logging with log/slog: JSON/Text handlers, levels, typed attrs, With/WithGroup, SetDefault, ReplaceAttr redaction |
141 |
tracecontext |
go run ./examples/month-06/tracecontext |
W3C Trace Context traceparent: trace-id vs span-id, parent/child hops, sampling flag, strict parsing |
143 |
healthcheck |
go run ./examples/month-06/healthcheck |
liveness vs readiness vs shutdown: /healthz ignores deps, /readyz aggregates them and drains on shutdown |
144 |
correlation |
go run ./examples/month-06/correlation |
correlation IDs end to end: middleware extract-or-mint, context propagation, a context-reading slog.Handler |
145 |
Day 142 (Prometheus
client_golang) and Day 143's OpenTelemetry SDK need third-party libraries, so their real APIs live as snippets in the day notes; the stdlibtracecontextexample covers the propagation format that ties traces together.
Week 2 — packaging, CI, config, shutdown¶
| Topic | Run | Teaches | Day |
|---|---|---|---|
buildinfo |
go run ./examples/month-06/buildinfo |
version stamping: runtime/debug.ReadBuildInfo + an ldflags-overridden var (VCS revision, deps) |
148 |
config |
go run ./examples/month-06/config |
12-factor config: typed env parse, defaults, accumulate-and-errors.Join validation, fail-fast |
152 |
secrets |
go run ./examples/month-06/secrets |
*_FILE-first secret resolution (Docker/K8s pattern) + redaction for safe logging |
152 |
graceful |
go run ./examples/month-06/graceful (Ctrl-C) |
signal-driven graceful HTTP shutdown: signal.NotifyContext + srv.Shutdown(ctx) draining in-flight requests |
153 |
Docker multi-stage builds,
docker compose, distroless hardening, and GitHub Actions (Days 148–151) are tooling/config, not Go code — their Dockerfile,compose.yaml, andci.ymlsnippets live inline in the day notes.
Week 3 — profiling, allocations, optimization, rate limiting¶
| Topic | Run | Teaches | Day |
|---|---|---|---|
pprof |
go run ./examples/month-06/pprof |
collect CPU & heap profiles with runtime/pprof; the net/http/pprof endpoint for live services; what go tool pprof reads |
155 |
escape |
go run ./examples/month-06/escape |
escape analysis: stack vs heap, measuring with testing.AllocsPerRun, seeing the compiler's decision via -gcflags=-m |
156 |
syncpool |
go run ./examples/month-06/syncpool |
sync.Pool to reuse allocations on a hot path; Reset-after-Get discipline; GC-may-drain caveats |
157 |
ratelimit |
go run ./examples/month-06/ratelimit |
token-bucket rate limiter from scratch; burst vs rate; HTTP middleware + 429/Retry-After shape |
160 |
Load testing (k6 / vegeta, Day 158),
govulncheck/gosec(Day 159), and the AuthN/Z hardening on Day 160 are CLI tools and HTTP middleware whose real APIs live inline in the day notes (k6 is JS, vegeta/govulncheck/gosecare external commands). The stdlibratelimitexample covers the rate-limiting algorithm itself.
Week 4 — capstone architecture¶
| Topic | Run | Teaches | Day |
|---|---|---|---|
architecture |
go run ./examples/month-06/architecture |
ports & adapters / dependency inversion: a Service depending on a Repository interface, with an in-memory adapter swappable for Postgres; sentinel wrapping with %w |
162 |
restapi |
go run ./examples/month-06/restapi |
the REST transport layer with Go 1.22 net/http method+wildcard routing (POST /links, GET /links/{code}), JSON DTOs, DisallowUnknownFields, driven by an in-process httptest.Server |
163 |
cacheaside |
go run ./examples/month-06/cacheaside |
the cache-aside read path (the Redis layer's concept) as a bounded LRU + TTL cache built from container/list + sync.Mutex, with a GetOrLoad loader |
164 |
The capstone's gRPC API, Postgres (pgx) persistence, Redis cache, Prometheus metrics, and OpenTelemetry tracing need third-party SDKs, so their real APIs live as snippets in the Day 162–167 notes; these stdlib programs teach the underlying shapes (layering, routing, cache-aside) those libraries plug into.
Every program imports only the standard library.