go-context

Standardize Go context usage to prevent leaks and improper propagation.

139|17|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/cxuu/golang-skills --skill go-context
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-context
Source: https://github.com/cxuu/golang-skills/tree/main/skills/go-context
Command: npx skills add https://github.com/cxuu/golang-skills --skill go-context

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go context patterns standardize how context.Context is passed and avoid common pitfalls like leaking contexts or storing them in structs.

Core Features & Use Cases

  • Clear guidelines for using context.Context as the first parameter
  • Best practices for cancellation, deadlines, and value propagation across call boundaries
  • Real-world use cases such as API handlers, background workers, and long-running tasks

Quick Start

Implement a simple Go function that takes a context as the first parameter and demonstrate cancellation with a timeout.

Frequently Asked Questions about go-context

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

FAQPage Schema
How do I prevent context leaks in Go applications?

To prevent context leaks in Go, standardize context.Context usage by passing it as the first parameter and avoiding storing contexts in structs. This ensures proper cancellation, deadlines, and value propagation across function boundaries.

Why should context.Context be the first parameter in Go functions?

context.Context should be the first parameter to ensure consistent propagation across function boundaries. This standard practice enforces clear guidelines for cancellation, deadlines, and value passing without leaking contexts or creating custom Context types.

What is the best way to handle context cancellation and deadlines in Golang?

The best way to handle context cancellation and deadlines in Golang is to pass context.Context explicitly as the first function parameter. This standardizes propagation across call boundaries for API handlers and long-running tasks.

Can I store a Go context inside a struct?

You should not store a Go context inside a struct. Storing contexts in structs causes improper propagation and potential leaks; instead, pass context.Context explicitly as the first parameter across function boundaries.

When do I need to use context propagation in Go background workers?

You need context propagation in Go background workers when managing cancellation, deadlines, and value passing across call boundaries. Standardizing context.Context as the first parameter ensures long-running tasks can terminate cleanly without leaking.