From claude-resources
Go context propagation, cancellation, timeouts, and value storage. Use when managing request lifecycles, implementing timeouts, or coordinating goroutine cancellation. 100% Go-specific.
npx claudepluginhub deandum/claude-resources --plugin go-skillsThis skill uses the workspace's default tool permissions.
Context is the first parameter, flows through call chains, never lives in structs.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides agent creation for Claude Code plugins with file templates, frontmatter specs (name, description, model), triggering examples, system prompts, and best practices.
Context is the first parameter, flows through call chains, never lives in structs.
| Create Context | Use Case |
|---|---|
context.Background() | Top-level (main, tests, init) |
context.TODO() | Placeholder when unclear |
WithTimeout(parent, d) | Operations with time limits |
WithCancel(parent) | Manual cancellation needed |
WithDeadline(parent, t) | Absolute deadline |
WithValue(parent, k, v) | Request-scoped data |
WithoutCancel(parent) | Detach from parent cancellation (Go 1.21+) |
func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()
user, err := h.repo.FindByID(ctx, userID)
if errors.Is(err, context.DeadlineExceeded) {
http.Error(w, "request timeout", http.StatusGatewayTimeout)
return
}
}
type contextKey string
const traceIDKey contextKey = "trace_id"
func WithTraceID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, traceIDKey, id)
}
func GetTraceID(ctx context.Context) (string, bool) {
id, ok := ctx.Value(traceIDKey).(string)
return id, ok
}
Rules: custom type for keys, accessor functions for type safety, context values = request-scoped immutable data only.
| Context Values | Explicit Parameters |
|---|---|
| Request metadata (trace IDs, correlation IDs) | Business logic parameters |
| Auth credentials (user ID, tokens) | Function behavior config |
| Cross-cutting concerns (logging, tracing) | Domain data and entities |
// Post-response async work that must not cancel with the HTTP request
go h.mailer.SendConfirmation(context.WithoutCancel(r.Context()), order)
Preserves parent's values (trace ID) but outlives parent's cancellation.
ctx.Done() in loopscontext.Context is the first parameter in every function that accepts onecontext.Context stored in struct fieldsstring)WithTimeout/WithCancel always paired with defer cancel()