What problem does it solve?
Go applications often struggle to propagate cancellation, deadlines, and request-scoped values across layers. This skill codifies idiomatic practices for using context.Context in Go, including propagation through HTTP handlers, services, and data stores, and avoiding common pitfalls like storing contexts in structs or bypassing context-aware APIs.
Core Features & Use Cases
- Propagate cancellation and deadlines across HTTP, gRPC, and background tasks using WithCancel, WithTimeout, and WithDeadline.
- Use context values judiciously for trace IDs and request-scoped metadata, without abusing context for business parameters.
- Ensure all downstream calls (HTTP, database) use context-aware APIs (e.g., Do with Request with Context, QueryContext/ExecContext/QueryRowContext).
Quick Start
Refactor a Go service to consistently pass and propagate a context.Context through handlers, services, and database calls, avoiding storing Context in structs.