What problem does it solve?
Prevents broken cancellation, leaking timers, and incorrect request-scoped value handling by enforcing idiomatic context.Context propagation across Go API boundaries.
Core Features & Use Cases
- Correct context propagation: Keep the same ctx through the full call chain (HTTP handler → services → DB → external calls) to ensure cancellations and deadlines work end-to-end.
- Resource-safe derived contexts: Use context.WithCancel, context.WithTimeout, and context.WithDeadline with guaranteed cancel() calls to avoid leaked timers and lingering goroutines.
- Safe request-scoped values: Store only request-scoped metadata in context values using unexported key types to avoid collisions, and use context.WithoutCancel for background work that must outlive the request.
- Practical guidance for Go codebases: Includes actionable rules for ctx placement (first parameter), placeholder choice (context.TODO vs context.Background), HTTP/client/db context-aware APIs, and common failure modes.
Quick Start
Ask your AI coding agent to refactor your Go code to propagate request context correctly from handlers through database and HTTP client calls, including proper WithTimeout cancel() usage and safe context values.