asarchami/dotfiles/go-context
- community
Checking that the SKILL.md file is still in the repository.
Go context.Context — propagate the request's session: creation, propagation, cancellation, timeouts, deadlines, request-scoped values, trace context. Use when writing or reviewing any Go code that takes or passes context, touches a database, or spawns goroutines.
Install
npx vskill@latest install asarchami/dotfiles/go-contextSKILL.md
Go Context
Leading word: propagate. context.Context is the request's session — the cancellation signal, deadline, and request-scoped data that every operation in the same unit of work shares. The discipline is one verb: propagate the same context through the whole chain, and derive from it only with a deferred cancel.
Steps
- Take ctx first. Every function that reaches a database, an external API, or a goroutine takes
ctx context.Contextas its first parameter.
Done when: no function on the call path reaches an external side effect without receiving ctx.
- Propagate, don't recreate. Pass the caller's context down the chain.
context.Background()belongs only at entry points (main, init, tests);context.TODO()is a placeholder while wiring.
Done when: no `context.Background()` or `context.TODO()` appears in the middle of a request path.
- Derive with a deferred cancel.
WithCancelfor manual control,WithTimeoutfor a duration,WithDeadlinefor an absolute time — anddefer cancel()on the same line you derive.
Done when: every derived context has its cancel deferred immediately; `go vet` reports nothing.
- Bound the values. Carry only request-scoped metadata (request ID, user ID) as context values under an unexported key type. Function parameters and struct fields are the wrong home for them.
Done when: every value key is an unexported type and the value is request metadata, not a parameter.
- Start from the source. Handlers use
r.Context(); database calls use the*Contextvariants (QueryContext,ExecContext); client calls useNewRequestWithContext.
Done when: the request's context reaches every downstream call without a fresh Background or TODO.
- Detach with intent. Work that must outlive the request roots itself in the parent context with
context.WithoutCancel(Go 1.21+) — never a newly created Background.
Done when: background work is detached via WithoutCancel, not disconnected.
Reference
| Situation | Create | |
|---|---|---|
| Entry point (main, init, test) | context.Background() | |
| Caller doesn't provide one yet | context.TODO() | |
| Inside an HTTP handler | r.Context() | |
| Manual cancellation | context.WithCancel(parent) | |
| Deadline or timeout | context.WithTimeout(parent, d) / context.WithDeadline(parent, t) |
- [Cancellation, Timeouts & Deadlines](./references/cancellation.md) — propagation mechanics,
<-ctx.Done(),AfterFunc,WithoutCancel - [Values & Cross-Service Tracing](./references/values-tracing.md) — unexported keys, OpenTelemetry trace headers, correlation IDs
- [HTTP Servers & Service Calls](./references/http-services.md) — handler context, client timeouts,
*ContextDB variants
Watch for
| Failure | Positive | |
|---|---|---|
context.Background() mid-request | Propagate the caller's context | |
nil context passed | context.TODO() when uncertain | |
| Context stored in a struct | Pass explicitly through parameters | |
cancel() not deferred | defer cancel() on the derivation line | |
| Exported value key (collision-prone) | Unexported key type |
Cross-references
- → See
go-concurrencyfor goroutine cancellation with context - → See
go-databaseforQueryContext/ExecContext - → See
go-observabilityfor OpenTelemetry trace propagation - → See
go-patternsfor timeout and resilience patterns - → See
go-lintforgovet/staticcheckenforcement
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdot_config/opencode/skills/go/go-context/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/asarchami/dotfiles/go-context)