ecc-golang-patterns

Provides idiomatic Go patterns for errors, interfaces, concurrency, and package structure.

Updated Apr 18, 2025
One-click install
npx skills add https://github.com/adriancodes/dotfiles --skill ecc-golang-patterns-adriancodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ecc-golang-patterns
Source: https://github.com/adriancodes/dotfiles/tree/main/dot_agents/skills/ecc-golang-patterns
Command: npx skills add https://github.com/adriancodes/dotfiles --skill ecc-golang-patterns-adriancodes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Go code that follows community idioms is hard without a reference, especially for error wrapping, goroutine lifecycle management, and interface design. This Skill supplies a curated set of Go patterns so code reviews, refactors, and new implementations stay consistent and maintainable. ## Core Features & Use Cases - Error Handling Patterns: Covers error wrapping with fmt.Errorf, custom error types, sentinel errors, and errors.Is/errors.As checks. - Concurrency Patterns: Includes worker pools, context-based cancellation and timeouts, graceful shutdown, errgroup coordination, and goroutine leak prevention. - Design Guidance: Provides interface design rules, functional options, struct embedding, package layout, and performance tips like slice preallocation and sync.Pool. - Use Case: When reviewing a Go service that spawns goroutines without cancellation handling, use this Skill to apply the safeFetch and errgroup patterns to eliminate leaks. ## Quick Start Ask the assistant to review your Go file for idiomatic error handling and concurrency issues using the Go patterns reference.

Frequently Asked Questions about ecc-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, then check them with errors.Is for sentinel values and errors.As for typed errors. Never ignore errors with the blank identifier unless the reason is explicitly documented.

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 close result channels after workers finish.

Should Go functions return interfaces or structs?▼

Functions should accept interfaces as parameters and return concrete struct types. Define interfaces in the consumer package where they are used, keeping them small and focused, often with a single method.

What is the functional options pattern in Go?▼

The functional options pattern configures a struct by passing variadic Option functions to its constructor, each setting one field. It provides sensible defaults while keeping the API extensible without breaking existing callers.

When should I use context.Context in Go functions?▼

Pass context.Context as the first parameter of any function that performs I/O, network calls, or long-running work. Use context.WithTimeout for deadlines and never store context inside a struct.