go-patterns

Apply idiomatic Go patterns for interfaces, errors, concurrency, and testing.

9|2|Updated Dec 5, 2025
One-click install
npx skills add https://github.com/Zate/cc-plugins --skill go-patterns-zate
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-patterns
Source: https://github.com/Zate/cc-plugins/tree/main/plugins/devloop/skills/go-patterns
Command: npx skills add https://github.com/Zate/cc-plugins --skill go-patterns-zate

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing clean, efficient, and concurrent Go code requires adherence to idiomatic patterns and best practices. Without clear guidance, Go projects can suffer from goroutine leaks, race conditions, and poor error handling.

Core Features & Use Cases

  • Interface Design: Master small, focused interfaces and the "accept interfaces, return structs" principle.
  • Error Handling: Implement robust error wrapping, sentinel errors, and custom error types for clear diagnostics.
  • Concurrency Patterns: Safely use goroutines with WaitGroup, worker pools, and context for cancellation and deadlines.
  • Testing Patterns: Write effective table-driven tests, test helpers, and interface-based mocking for comprehensive coverage.
  • Functional Options: Design configurable constructors for flexible and extensible APIs.
  • Use Case: Design a concurrent worker pool, implement robust error handling for an API, or write a table-driven test for a utility function.

Quick Start

Implement a Go function that reads from an io.Reader and returns an error, demonstrating proper error wrapping and context propagation.

Frequently Asked Questions about go-patterns

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

FAQPage Schema
How do I write idiomatic Go code that follows best practices?

Idiomatic Go emphasizes simplicity, small focused interfaces, explicit error handling, and the "accept interfaces, return structs" principle. Go patterns guide you through interface design, error wrapping with context, and concurrency safety using goroutines, WaitGroup, and context cancellation to build reliable, high-performance services aligned with Go 1.21+ conventions.

What's the best way to handle errors in Go?

Robust error handling in Go uses error wrapping to preserve context, sentinel errors for specific conditions, and custom error types for diagnostics. This approach enables callers to inspect and respond to failures appropriately while maintaining a clear error chain throughout your application.

How do I safely use goroutines and avoid race conditions?

Safe concurrency in Go uses WaitGroup for synchronization, worker pools for bounded parallelism, and context for cancellation and deadlines. These patterns prevent goroutine leaks, eliminate race conditions, and ensure graceful shutdown of concurrent workloads in services and libraries.

What are table-driven tests and why should I use them?

Table-driven tests organize test cases as data structures, reducing boilerplate and improving coverage clarity. This pattern, combined with test helpers and interface-based mocking, enables comprehensive testing of Go functions and utilities with minimal code duplication.

How do I design flexible and configurable Go APIs?

The functional options pattern uses option functions to configure constructors, enabling extensible APIs without breaking changes. This approach lets callers set only the settings they need, keeping constructor signatures clean while supporting future feature additions.

What concurrency patterns prevent goroutine leaks in production Go services?

Goroutine leaks occur when background tasks never terminate. Context-based cancellation, WaitGroup coordination, and worker pools with bounded channels prevent leaks by ensuring all spawned goroutines exit cleanly when the parent service shuts down.