npx skills add ...
npx skills add cxuu/golang-skills --skill go-context
Use when working with context.Context in Go — placement in signatures, propagating cancellation and deadlines, and storing values in context vs parameters. Also use when cancelling long-running operations, setting timeouts, or passing request-scoped data, even if they don't mention context.Context directly. Does not cover goroutine lifecycle or sync primitives (see go-concurrency).
npx skills add cxuu/golang-skills --skill go-context
Compatibility:
contexthas been in the standard library since Go 1.7.
references/PATTERNS.md - Read when deriving contexts, checking cancellation, handling HTTP request contexts, or using typed context-value keys.Functions that use a Context should accept it as their first parameter:
This is a strong convention in Go that makes context flow visible and consistent across codebases.
Do not add a Context member to a struct type. Instead, pass ctx as a parameter
to each method that needs it:
Exception: Methods whose signature must match an interface in the standard library or a third-party library may need to work around this.
Do not create custom Context types or use interfaces other than context.Context
in function signatures:
Consider these options in order of preference:
Context values are appropriate for:
Context values are not appropriate for:
Always defer cancel() immediately after creating a derived context:
Contexts are immutable — it's safe to pass the same ctx to multiple
concurrent calls that share the same deadline and cancellation signal.
ctx.Err() cancellation errors