go-context

Standardize context.Context propagation as the first parameter in Go functions.

Updated Feb 28, 2026
One-click install
npx skills add https://github.com/rondevz/phant --skill go-context-rondevz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-context
Source: https://github.com/rondevz/phant/tree/main/.agents/skills/go-context
Command: npx skills add https://github.com/rondevz/phant --skill go-context-rondevz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go programs often mis-handle context.Context, leading to brittle APIs, unclear cancellation, and improper propagation across boundaries. This skill standardizes how contexts are passed and propagated to improve readability and reliability.

Core Features & Use Cases

  • Enforces placing context.Context as the first parameter of functions/methods.
  • Advises against storing Context in structs and against custom context types.
  • Covers deriving, cancellation patterns, timeouts, and request-scoped values in server or library code.
  • Use case: you are building a REST API client or server in Go and need consistent cancellation and timeout handling.

Quick Start

Run examples that demonstrate proper context propagation in a handler and downstream calls.

Frequently Asked Questions about go-context

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

FAQPage Schema
How do I pass context.Context safely across API boundaries in Go?

Avoid storing context.Context in structs to prevent scope leaks. Instead, pass context as the first parameter of functions or methods to maintain cancellation propagation and request-scoped values explicitly across API boundaries.

Why does storing context in a struct cause issues in Go programs?

Storing context in structs breaks cancellation propagation and makes context lifetimes unclear. Passing context as the first function parameter avoids stale contexts and preserves proper request-scoped boundaries.

What is the best way to handle context cancellation and timeouts in Go HTTP handlers?

The best way to handle context cancellation and timeouts is by deriving contexts with explicit deadlines from the incoming request context. This ensures downstream calls respect server cancellation patterns and request-scoped timeouts.

Can I create custom context types for request-scoped values in Go?

You should avoid creating custom context types. Standardizing on the standard library context.Context and using explicit derivation for request-scoped values ensures compatibility and prevents brittle APIs.

Does this approach to context management work for both Go libraries and server code?

Yes, standardizing context propagation works for both Go libraries and HTTP server code. It enforces consistent context management, allowing both environments to handle cancellation, deadlines, and request-scoped values reliably.