golang-patterns

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill golang-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/golang-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill golang-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Go code that follows community conventions is hard without a reference for idiomatic patterns, leading to non-idiomatic error handling, goroutine leaks, and poorly designed interfaces. ## 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 optimization. - 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 prevent leaks. ## Quick Start Review my Go HTTP server code and apply idiomatic patterns for error handling and graceful shutdown.

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 to 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, which is the most common leak source.

Should Go functions accept interfaces or structs?

Functions should accept interfaces as parameters and return concrete struct types. Define small, focused interfaces in the consumer package where they are used, not in the provider package.

What is the functional options pattern in Go?

The functional options pattern uses variadic Option functions to configure a struct, letting callers set only the fields they need while defaults apply to the rest. It avoids long constructor parameter lists and keeps APIs extensible.

When should I use errgroup instead of sync.WaitGroup?

Use errgroup when you need to run multiple goroutines and collect the first error, since it combines WaitGroup coordination with error propagation and context cancellation. Plain WaitGroup only waits for completion without error handling.

What linters should I enable for a Go project?

Enable errcheck, gosimple, govet, ineffassign, staticcheck, unused, gofmt, and goimports in golangci-lint. Run go vet and go test -race alongside these for static analysis and race detection.