golang-patterns

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

2|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/adamreger/ecc-antigravity --skill golang-patterns-adamreger
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/adamreger/ecc-antigravity/tree/main/skills/golang-patterns
Command: npx skills add https://github.com/adamreger/ecc-antigravity --skill golang-patterns-adamreger

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 structured packages. ## 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, apply the safe fetch and errgroup patterns to eliminate goroutine leaks and add proper timeout handling. ## Quick Start Review my Go code in the internal/service package and refactor it to follow idiomatic Go 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 for sentinel values and errors.As for typed errors.

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. Coordinate multiple goroutines with errgroup or sync.WaitGroup, and always ensure channels are closed by their sender.

What is the standard Go project layout?▼

Place entry points in cmd/, private application code in internal/ (handler, service, repository, config), public libraries in pkg/, API definitions in api/, and test fixtures in testdata/. Keep package names short, lowercase, and free of underscores.

Should Go functions accept interfaces or structs?▼

Functions should accept interfaces and return concrete struct types. Define small, focused interfaces in the consumer package where they are used, not in the provider package, and compose larger interfaces from single-method ones like Reader and Writer.

When should I use the functional options pattern in Go?▼

Use functional options when a constructor has many optional parameters with sensible defaults, such as server timeouts or loggers. Define an Option type as func(*T), provide WithX helpers, and apply them in a variadic constructor.

What linters should I run on Go code?▼

Run go vet, staticcheck, and golangci-lint with linters like errcheck, gosimple, ineffassign, unused, gofmt, and goimports. Also run go test with -race and -cover flags to detect data races and measure coverage.