golang-context

Enforce proper context.Context usage for cancellation, deadlines, and value propagation in Go code.

23|1|Updated May 10, 2026
One-click install
npx skills add https://github.com/berksunduri/GOPost --skill golang-context-berksunduri
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-context
Source: https://github.com/berksunduri/GOPost/tree/main/.agents/skills/golang-context
Command: npx skills add https://github.com/berksunduri/GOPost --skill golang-context-berksunduri

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the common challenges in Golang applications when using context.Context for request-scoped cancellation, deadlines, and value propagation across API boundaries.

Core Features & Use Cases

  • Context Propagation: Ensures consistent propagation of context across different layers of a Golang application.
  • Cancellation & Timeouts: Guides the use of cancellation signals and deadlines for managing request lifecycles effectively.
  • Best Practices: Provides guidelines for using context.Context to avoid common pitfalls like context leaks, incorrect cancellation handling, and misuse of background contexts.
  • Use Case: When designing APIs with request-scoped contexts, debugging context leaks, or selecting the appropriate context variant for different scenarios.

Quick Start

Analyze your Golang service's context usage with the golang-context skill.

Frequently Asked Questions about golang-context

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

FAQPage Schema
How do I propagate context.Context across different layers of a Golang application?

Propagating context.Context across Golang application layers requires passing it as the first parameter to downstream functions. This ensures consistent context propagation for request-scoped data, cancellation signals, and deadlines across API boundaries.

How does context.Context handle request cancellation and deadlines in Go APIs?

Context.Context handles request cancellation and deadlines in Go APIs by carrying cancellation signals and timeout values across execution boundaries. This mechanism manages request lifecycles effectively, terminating asynchronous operations or external API calls when deadlines expire.

What are common context.Context pitfalls and leaks when designing Golang services?

Common context.Context pitfalls in Golang services include context leaks, incorrect cancellation handling, and misusing background contexts. Avoiding these requires following best practices for context propagation and selecting the appropriate context variant for different scenarios.

When do I need to use context.Context for asynchronous operations and database interactions?

You need context.Context for asynchronous operations, external API calls, and database interactions in Go when requiring context-based control over execution flow. It provides request-scoped cancellation, deadlines, and value propagation across API boundaries.

Can I use this golang-context approach for services with external API calls and database interactions?

Yes, this approach is suitable for Golang services with asynchronous operations, external API calls, and database interactions. It enforces proper context.Context usage, providing context-based control over execution flow and managing request lifecycles.

Why does my Golang code lose cancellation signals across API boundaries?

Golang code loses cancellation signals across API boundaries due to incorrect context propagation. When context.Context is not passed correctly to downstream functions, cancellation signals and deadlines fail to reach asynchronous operations or external API calls.