go-context
Skill7 starsChanged 9 days agoApache-2.0View on GitHub
Use when handling Go context.Context, cancellation, deadlines, timeouts, or request-scoped values and parameter placement. Goroutine lifecycle and synchronization belong to go-concurrency.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- eduardo-sl/go-agent-skillstheir own version, first seen Nov 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- eduardo-sl/go-agent-skills★ 85same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- go-code-refactorSkill
- go-code-reviewSkill
- go-codeSkill
- go-concurrencySkill
- go-databaseSkill
- go-data-structuresSkill
- go-defensiveSkill
- go-documentationSkill
- go-error-handlingSkill
- go-functionsSkill
- go-genericsSkill
- go-httpSkill
- go-interfacesSkill
- go-lintingSkill
- go-loggingSkill
- go-namingSkill
- go-packagesSkill
- go-performanceSkill
- go-resilienceSkill
- go-securitySkill
- go-style-coreSkill
- go-testingSkill
- go-troubleshootingSkill
The file
Files
Go Context Usage
Compatibility: Baseline Go 1.27 (see COMPATIBILITY.md).
context.WithoutCancel,context.AfterFunc,context.WithTimeoutCauseandcontext.WithDeadlineCauserequire Go 1.21+;t.Context()in tests, Go 1.24+.
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 accept it as their first parameter. Do not
add a Context member to a struct type (containedctx in the gate reports it);
pass ctx to each method that needs it. Exception: methods whose signature must match an interface in the
standard library or a third-party library. Do not create custom Context types
or use interfaces other than context.Context in function signatures.
Where to Put Application Data
Parameters first, then the receiver, then a global; a context value carries
only request-scoped data that crosses APIs — a request or trace ID, the
authenticated principal — never an optional parameter, per-process
configuration, or a deadline, which is derived with WithTimeout,
WithDeadline, or WithCancel.
Common Patterns
Deriving Contexts
defer cancel() immediately after creating a derived context. Inside a loop a
defer waits for the function to return, so every iteration's context stays
live until then: cancel at the end of each iteration, or move the iteration
into its own function that defers cancel().
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
for _, item := range items {
itemCtx, cancelItem := context.WithTimeout(ctx, time.Second)
err := send(itemCtx, item)
cancelItem() // per iteration, not deferred
if err != nil {
return err
}
}Cancellation With a Reason
With context.WithCancelCause, WithTimeoutCause, or WithDeadlineCause,
ctx.Err() still returns Canceled or DeadlineExceeded; only
context.Cause(ctx) returns the reason supplied, so a caller that must tell
this cancellation or timeout from an upstream one reads Cause.
WithCancelCause returns a CancelCauseFunc, released on the success path
with defer cancel(nil); WithTimeoutCause and WithDeadlineCause return a
plain CancelFunc (defer cancel()), and their cause is set only when the
timer fires.
context.WithoutCancel(ctx) keeps the values but drops cancellation; use it
for work that must outlive the request (audit log, cleanup) and give that work
its own timeout.
Related Skills
- go-resilience: total and attempt time budgets, cancellation-aware backoff, durable retry ownership.
- go-concurrency: goroutine cancellation, select timeouts, errgroup.
- Returning
ctx.Err()orcontext.Cause(ctx): Cancellation With a Reason above. - go-interfaces: APIs that take context alongside interfaces.
- go-logging: loggers and request IDs carried in context.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

