golang-patterns

Apply idiomatic Go patterns for error handling and concurrency.

Updated Sep 13, 2025
One-click install
npx skills add https://github.com/llmh333/employee_management_spring --skill golang-patterns-llmh333
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/llmh333/employee_management_spring/tree/main/.gemini/skills/golang-patterns
Command: npx skills add https://github.com/llmh333/employee_management_spring --skill golang-patterns-llmh333

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the problem of inconsistent, error-prone Go code by providing practical, idiomatic patterns that improve readability, reliability, and maintainability.

Core Features & Use Cases

  • Idiom-first coding guidance: Apply core Go principles like simplicity, clear naming, and making the zero value useful to reduce bugs.
  • Production-ready error handling: Use wrapping with context plus errors.Is/errors.As, along with sentinel and custom error types for predictable control flow.
  • Concurrency done safely: Implement worker pools, cancellation/timeouts with context, graceful shutdown, and errgroup coordination while avoiding goroutine leaks.
  • Interface and package design: Accept interfaces, return concrete types, design small focused interfaces, and organize packages using standard layouts.
  • Performance-minded structuring: Use preallocation, sync.Pool, and avoid inefficient patterns like string concatenation in loops.

Quick Start

Ask the AI to review a Go function for idiomatic style, correct error handling (wrapping plus errors.Is/errors.As), and safe concurrency based on the patterns in golang-patterns.

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 in Go using wrapping and errors.Is?

Go error handling should wrap errors with context using `fmt.Errorf` and unwrap them using `errors.Is` or `errors.As`. This approach ensures predictable control flow while preserving the original error type for targeted checks across package boundaries.

What is the best way to prevent goroutine leaks in Go concurrency?

Preventing goroutine leaks requires implementing worker pools, cancellation signals via `context`, and graceful shutdown mechanisms. Coordinating these with `errgroup` ensures safe concurrency by properly managing lifecycle and avoiding orphaned goroutines.

How do I structure Go interfaces for clean package design?

Structuring Go interfaces requires accepting interfaces, returning concrete types, and designing small, focused interfaces. This pattern reduces coupling and improves maintainability by ensuring consumers define the specific behavior they depend on.

When do I need to use sync.Pool and preallocation for Go performance?

You need `sync.Pool` and preallocation when optimizing Go performance to reduce garbage collection overhead. These patterns avoid inefficient memory allocations, particularly replacing string concatenation in loops with faster alternatives.

Does making the zero value useful reduce bugs in Go?

Making the zero value useful reduces bugs by ensuring Go types are immediately safe and operational without explicit initialization. This idiom simplifies struct construction and prevents nil pointer dereferences or invalid state.