golang-patterns

Provides idiomatic Go patterns for error handling, concurrency, interfaces, and package design.

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/JohnRebellion/.claude-public --skill golang-patterns-johnrebellion
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/JohnRebellion/.claude-public/tree/main/claude/skills/golang-patterns
Command: npx skills add https://github.com/JohnRebellion/.claude-public --skill golang-patterns-johnrebellion

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Go code that follows community conventions is hard without a reference for idiomatic patterns, and inconsistent error handling, goroutine leaks, and poor interface design lead to fragile applications. ## Core Features & Use Cases - Error Handling Patterns: Error wrapping with context, custom error types, sentinel errors, and errors.Is/errors.As checking. - Concurrency Patterns: Worker pools, context-based cancellation and timeouts, graceful shutdown, errgroup coordination, and goroutine leak prevention. - Design Guidance: Interface design, package organization, functional options pattern, struct embedding, and memory/performance optimizations like sync.Pool and slice preallocation. - Use Case: When reviewing a Go service that spawns goroutines without cancellation support, use this Skill to refactor it with context propagation and buffered channels to eliminate goroutine leaks. ## Quick Start Review my Go code and apply idiomatic patterns for error handling and concurrency.

Frequently Asked Questions about golang-patterns

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

FAQPage Schema
How do I handle errors idiomatically in Go?▼

Wrap errors with context using fmt.Errorf and the %w verb, define sentinel errors with errors.New for common cases, and create custom error types for domain-specific failures. Check errors with errors.Is and errors.As rather than string comparison, and never ignore errors with the blank identifier.

How do I prevent goroutine leaks in Go?▼

Use buffered channels or select statements with ctx.Done() so goroutines can exit when the context is cancelled. An unbuffered channel send blocks forever if no receiver exists, so always provide a cancellation path and coordinate shutdown with sync.WaitGroup or errgroup.

Should Go functions accept interfaces or structs?▼

Functions should accept interfaces and return concrete structs. Define small, focused interfaces in the consumer package rather than the provider package, so implementations do not need to know about the interface they satisfy.

What is the functional options pattern in Go?▼

The functional options pattern configures a struct by passing variadic Option functions to a constructor, each setting one field. It provides sensible defaults while keeping the API extensible, avoiding large constructor parameter lists or config structs.

When should I use sync.Pool in Go?▼

Use sync.Pool for frequently allocated objects like bytes.Buffer in hot paths to reduce garbage collection pressure. Always reset the object before returning it to the pool, and avoid it for objects that are cheap to allocate or rarely reused.

What linters should I run on Go code?▼

Run go vet, staticcheck, and golangci-lint with linters like errcheck, gosimple, ineffassign, unused, and gofmt enabled. Combine these with go test -race for race detection and go mod tidy to keep module dependencies clean.