go-context

Enforce correct context.Context propagation in Go code with typed keys and deferred cancel calls.

8|Updated Jun 5, 2026
One-click install
npx skills add https://github.com/muratmirgun/gophers --skill go-context-muratmirgun
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-context
Source: https://github.com/muratmirgun/gophers/tree/main/skills/go-context
Command: npx skills add https://github.com/muratmirgun/gophers --skill go-context-muratmirgun

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design, propagate, and debug context.Context usage in Go so cancellation, deadlines, and request-scoped values flow correctly through your application.

Core Features & Use Cases

  • Context Propagation: Keeps ctx as the first parameter and preserves the caller's cancellation chain across services, databases, HTTP clients, and goroutines.
  • Safe Request-Scoped Values: Shows how to use unexported key types and typed helpers for request IDs, auth principals, and tracing metadata without collisions.
  • Cancellation and Background Work: Covers WithCancel, WithTimeout, AfterFunc, and WithoutCancel for long-running tasks, retries, and fire-and-forget work.
  • Use Case: A Go handler calls downstream services and DB queries with the same ctx, while an audit goroutine continues safely after the response finishes.

Quick Start

Use the go-context skill to review my Go code for incorrect context propagation, unsafe value keys, and missing cancellation handling.

Frequently Asked Questions about go-context

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I propagate context cancellation correctly across Go HTTP handlers and database calls?▼

To propagate context cancellation in Go, pass ctx as the first parameter to context-aware APIs like QueryContext and NewRequestWithContext, preserving the caller's cancellation chain across HTTP handlers and database calls.

Why does my Go goroutine continue running after the parent request is cancelled?▼

Goroutine execution after parent cancellation occurs when context is not propagated. Use WithCancel, WithTimeout, or WithoutCancel to manage background work, ensuring long-running tasks respect parent cancellation behavior or safely continue for fire-and-forget audit tasks.

What is the best way to store request-scoped values in Go context without collisions?▼

Storing request-scoped values in Go context safely requires using unexported key types and typed helper functions, preventing collisions for request IDs, auth principals, and tracing metadata across concurrent requests.

Do I need to call the cancel function if I use WithTimeout in Go?▼

Yes, you must call the generated cancel function using a defer statement when using WithTimeout in Go. Deferring the cancel call immediately releases resources and stops the context's timer once the operation completes.

Can I use Go context to stop downstream tracing flows when the parent request times out?▼

Yes, you can use Go context to stop downstream tracing flows. Enforcing correct context.Context propagation ensures that deadlines and cancellation signals automatically flow into HTTP client requests and tracing metadata.