Go context conventions covering placement, cancellation, deadlines, and when to store values in context.

CCM score
63 of 100
skills.sh installs
1.4K
GitHub stars
197
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers context.Context placement in signatures, propagating cancellation and deadlines, and storing request-scoped values
  • Includes a routing reference (references/PATTERNS.md) for deriving contexts, checking cancellation, HTTP request contexts, and typed value keys
  • Enforces context as the first parameter, no Context fields in structs, and no custom context types in signatures
  • Designed for Go developers working with timeouts, cancellation, or request-scoped data, and points to go-concurrency for goroutine lifecycle

Install

$ npx -y skills add cxuu/golang-skills --skill go-context -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Go Context Usage

Compatibility: context has been in the standard library since Go 1.7.

Resource Routing

  • references/PATTERNS.md - Read when deriving contexts, checking cancellation, handling HTTP request contexts, or using typed context-value keys.

Context as First Parameter

Functions that use a Context should accept it as their first parameter:

func F(ctx context.Context, /* other arguments */) error
func ProcessRequest(ctx context.Context, req *Request) (*Response, error)

This is a strong convention in Go that makes context flow visible and consistent across codebases.


Don't Store Context in Structs

Do not add a Context member to a struct type. Instead, pass ctx as a parameter to each method that needs it:

// Bad: Context stored in struct
type Worker struct {
    ctx context.Context  // Don't do this
}

// Good: Context passed to methods
type Worker struct{ /* ... */ }

func (w *Worker) Process(ctx context.Context) error {
    // Context explicitly passed — lifetime clear
}

Exception: Methods whose signature must match an interface in the standard library or a third-party library may need to work around this.


Details

Repository
github.com/cxuu/golang-skills
Category
Go
First seen
May 16, 2026

More from cxuu/golang-skills

All 20

Similar to Go Context

More Go