golang-context

Implement Go context.Context cancellation, propagation, and request-scoped data sharing.

Updated Apr 20, 2026
One-click install
npx skills add https://github.com/matdev83/go-llm-interactive-proxy --skill golang-context-matdev83
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-context
Source: https://github.com/matdev83/go-llm-interactive-proxy/tree/main/.agents/skills/golang-context
Command: npx skills add https://github.com/matdev83/go-llm-interactive-proxy --skill golang-context-matdev83

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires samber/cc-skills-golang, and includes references (resource) and scripts (resource) components.

What problem does it solve?

It provides best practices and techniques for managing context.Context in Go applications, improving request propagation and cancellation handling.

Core Features & Use Cases

  • Request lifecycle management: Ensures context is properly propagated through HTTP handlers, service layers, and database operations.
  • Cancellation & timeouts: Implements effective cancellation and deadlines for concurrent processes.
  • Trace and metadata propagation: Facilitates passing trace IDs, request IDs, and user info across system boundaries.
  • Use Case: For a microservices architecture, manage trace context and request cancellation seamlessly during external API calls and internal workflows.

Quick Start

Use the golang-context skill to implement context-aware HTTP server middleware and database functions that respect request deadlines and propagate trace information.

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 and trace IDs across microservices in Go?

To propagate context and trace IDs across microservices, you pass the context.Context through HTTP headers, service layers, and database operations. This ensures trace information and request-scoped data seamlessly cross system boundaries during external API calls.

What is the best way to handle timeouts and cancellation in Go concurrent processes?

Handling timeouts and cancellation in Go requires using context.WithTimeout or context.WithCancel. This ensures effective deadline management and signals concurrent processes and goroutines to terminate when an API request is aborted.

How do I manage request lifecycle context in Go HTTP handlers and database queries?

Managing request lifecycle context involves passing context.Context from HTTP server middleware directly into database query functions. This enforces safe context patterns, ensuring database operations respect request deadlines and avoid hanging.

Does this approach support distributed tracing for internal workflows in Go?

Yes, this approach supports distributed tracing by enforcing safe context patterns and trace propagation. It facilitates passing trace IDs and metadata across system boundaries, allowing seamless request cancellation and tracking during internal workflows.

Why does my Go API call hang when the client cancels the request?

Your Go API call hangs because the context is not properly propagated. Implementing effective cancellation and deadlines via context.Context ensures that concurrent processes and external API calls terminate immediately when the client request is canceled.