golang-context-patterns

golang-context-patterns is a skill for Cursor from codeready-toolchain/tarsy. It costs 39 tokens per session (2,262 once invoked), scanned A, original, Apache-2.0.

A set of recommended patterns for Go’s context package, which carries cancellation signals, time limits, and request data through a program. It covers HTTP requests, database work, and transactions.

In plain words
What is it for?
Use it when writing Go HTTP handlers, calling databases, managing transactions, or adding cancellation and timeout behavior.
Why use it?
It helps prevent work from continuing after a client disconnects or a timeout is reached. It also gives database operations a defined cancellation and time limit.

Skill for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when writing Go HTTP handlers, calling databases, managing transactions, or adding cancellation and timeout behavior.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/codeready-toolchain/tarsy/golang-context-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add codeready-toolchain/tarsy --skill golang-context-patterns
Clone the repo
git clone --depth 1 https://github.com/codeready-toolchain/tarsy

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for golang-context-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/codeready-toolchain/tarsy/golang-context-patterns.svg)](https://agentmods.dev/skills/codeready-toolchain/tarsy/golang-context-patterns)
Your own site
<a href="https://agentmods.dev/skills/codeready-toolchain/tarsy/golang-context-patterns"><img src="https://agentmods.dev/badge/skills/codeready-toolchain/tarsy/golang-context-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 39 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,262 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00039 $0.02262
Opus 5 $0.00019 $0.01131
Sonnet 5 $0.00008 $0.00452
Haiku 4.5 $0.00004 $0.00226

Measured 8d ago against content hash 63e8fb825c4c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

golang-context-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/skills/golang-context-patterns/SKILL.md · 380 lines

How it starts

The opening of the file, as written. The whole thing — 380 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Go Context Patterns

Context usage patterns for Go following 2025-2026 best practices.

Context Basics

Context carries:

  • Cancellation signals
  • Deadlines and timeouts
  • Request-scoped values

Golden rule: Always pass context as first parameter.

func DoWork(ctx context.Context, data string) error {
	// Pass ctx to all downstream operations
}

HTTP Handler Context

Extract from request:

func (s *Server) HandleRequest(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()  // Get request context
	
	// Context is cancelled if:
	// - Client disconnects
	// - Server timeout reached
	
	result, err := s.service.ProcessData(ctx, data)
	if err != nil {
		if errors.Is(err, context.Canceled) {
			// Client disconnected
			return
		}
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	
	json.NewEncoder(w).Encode(result)
}

Database Transaction Context Pattern

Critical pattern for TARSy:

func (s *SessionService) CreateSession(ctx context.Context, req CreateSessionRequest) (*ent.AlertSession, error) {
	writeCtx, cancel := context.WithTimeoutCause(
		context.Background(), 5*time.Second,
		fmt.Errorf("create session %s: db write timed out", req.SessionID),
	)
	defer cancel()
	
	tx, err := s.client.Tx(writeCtx)
	if err != nil {
		return nil, fmt.Errorf("failed to start transaction: %w", err)
	}
	defer func() { _ = tx.Rollback() }()
	
	session, err := tx.AlertSession.Create().
		SetID(req.SessionID).
		Save(writeCtx)
	if err != nil {
		return nil, fmt.Errorf("failed to create session: %w", err)
	}
	
	if err := tx.Commit(); err != nil {
		return nil, fmt.Errorf("failed to commit: %w", err)
	}
	
	return session, nil
}

Why background context for database operations:

  • HTTP request context might be cancelled if client disconnects
  • Database writes should complete even if client disconnects
  • Use separate timeout to prevent hanging forever

Context Timeout Patterns

WithTimeoutCause for operations with deadline:

func FetchData(ctx context.Context, url string) ([]byte, error) {
	ctx, cancel := context.WithTimeoutCause(ctx, 10*time.Second,
		fmt.Errorf("fetch %s timed out", url),
	)
	defer cancel()
	
	req, _ := http.NewRequestWithContext(ctx, "GET", url, nil)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	
	return io.ReadAll(resp.Body)
}

Read the full file on GitHub · 380 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 380 lines · 39 tokens per session scan A 63e8fb825c4c

Subscribe to this mod's changes

golang-context-patterns is a skill published in the GitHub repository codeready-toolchain/tarsy (10 stars, last pushed 4d ago), licensed Apache-2.0. It adds 39 tokens to every session and 2,262 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

fastapi-templates

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

wshobson/agents · 37 tokens

go

Use when writing, reviewing, testing, or shipping Go code and HTTP services: idioms, %w error wrapping, goroutine/context/errgroup concurrency, net/http 1.22 routing, log/slog, project layout, table-driven tests, Go hardening. NOT language-agnostic threat modeling (that is secure-coding), NOT Dockerfile/CI shipping…

ericrisco/rsc-harness · 86 tokens

vigilante-issue-implementation-on-go

Implement a GitHub issue end-to-end when Vigilante dispatches work for a Go repository with idiomatic tooling and security guidance.

aliengiraffe/vigilante · 36 tokens

goroutine-patterns

Implement Go concurrency patterns using goroutines, channels, and synchronization primitives. Use when building concurrent systems, implementing parallelism, or managing goroutine lifecycles. Trigger words include "goroutine", "channel", "concurrent", "parallel", "sync", "context".

armanzeroeight/fastagent-plugins · 60 tokens

pn-go-scaffolding

Scaffolds new Go API projects (Gin, Fiber, Echo, Chi) or handlers. Use when adding a new route/module; covers idiomatic project layout, env/secrets, error handling, and Go-specific conventions.

perniemann/pnCore · 51 tokens

golang-samber-do

Dependency injection in Golang using samber/do — service containers, lifecycle management, scopes, health checks, graceful shutdown, and module organization. Apply when using or adopting samber/do, when the codebase imports github.com/samber/do or github.com/samber/do/v2, or when refactoring manual constructor…

alexastrum/skl · 74 tokens