Go Context Best Practices

•
77
•

Implements idiomatic Go context patterns for handling timeouts, cancellations, and request-scoped data.

This skill equips Claude with specialized knowledge for managing Go's context.Context according to production standards from Google, Uber, and the wider Go community. It ensures contexts are passed correctly as the first parameter, prevents common anti-patterns like storing contexts in structs, and provides guidance on propagating deadlines and cancellation signals. It is an essential tool for developers building resilient Go services that need to handle long-running operations and complex request lifecycles efficiently.

Key Features

01Guides the correct usage of request-scoped data vs. explicit parameters
02Enforces Context as the first parameter in function signatures
03Provides patterns for proper context derivation using timeouts and deadlines
0477 GitHub stars
05Offers boilerplate for checking context cancellation in loops and HTTP handlers
06Prevents context storage in structs to ensure clear request lifetimes

Use Cases

01Passing tracing IDs and authentication tokens through request-scoped context
02Implementing timeouts for database queries and external API calls
03Propagating cancellation signals across multiple concurrent goroutines