Go Context Best Practices
Guides idiomatic context.Context propagation, cancellation, deadlines, and request-scoped values in Go applications.
Golang Context Best Practices equips Claude with deep domain knowledge for working with Go's `context.Context` package across complex architectures. It guides developers through end-to-end context propagation across HTTP boundaries and database calls, prevents common pitfalls like goroutine leaks and struct-stored contexts, establishes safe request-scoped value patterns with unexported keys, and leverages modern Go 1.21+ features like `context.WithoutCancel` for resilient background work.
Key Features
01Proper cancellation, deadline, and timeout lifecycles using WithCancel and WithTimeout
023,106 GitHub stars
03End-to-end request context propagation guidelines across HTTP, service, and database layers
04Integration patterns for HTTP handlers (r.Context), client requests, and SQL databases
05Background task detachment using Go 1.21+ context.WithoutCancel
06Collision-safe request-scoped value management using unexported key types
Use Cases
01Designing robust cancellation and timeout pipelines across microservices and databases
02Debugging leaked goroutines, unexpired contexts, and broken propagation chains
03Implementing safe correlation ID and OpenTelemetry trace propagation across API calls