Go Context Best Practices
Enforces idiomatic Go patterns for context.Context to manage timeouts, cancellations, and request-scoped data.
The Go Context Best Practices skill (cxuu) provides domain-specific guidance for implementing the Go context package according to official Go Wiki standards. It assists developers in maintaining consistent function signatures, preventing resource leaks through proper cancellation, and managing request-scoped values effectively. By following these patterns, developers can ensure their Go services handle timeouts and deadlines gracefully while avoiding common anti-patterns like storing contexts in structs or using them for optional parameters.
주요 기능
01Standardizes function signatures by enforcing context as the first parameter
02Prevents anti-patterns such as storing context within struct members
0351 GitHub stars
04Provides templates for deriving contexts with timeouts, deadlines, and cancellations
05Guides the proper usage of context values for request-scoped metadata
06Ensures immediate resource cleanup with defer cancel() patterns
사용 사례
01Injecting and retrieving request-scoped metadata like trace IDs and auth tokens
02Refactoring Go services to follow idiomatic context propagation and cancellation patterns
03Implementing timeouts and deadlines for resilient external API calls and database queries