golang-patterns

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

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/Oruga420/claude-code-skills --skill golang-patterns-oruga420
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/Oruga420/claude-code-skills/tree/main/golang-patterns
Command: npx skills add https://github.com/Oruga420/claude-code-skills --skill golang-patterns-oruga420

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go codebases often suffer from inconsistent style, fragile concurrency, unclear error handling, and poor package organization; this Skill provides concise, idiomatic patterns and practical guidance to make Go code predictable, maintainable, and efficient.

Core Features & Use Cases

  • Idiomatic Patterns: Guidance on zero-value design, accepting interfaces and returning structs, small focused interfaces, and clear naming.
  • Error Handling: Best practices for wrapping errors with context, using sentinel and custom error types, and checking errors with errors.Is and errors.As.
  • Concurrency & Stability: Patterns for worker pools, context-based cancellation and timeouts, errgroup coordination, and avoiding goroutine leaks.
  • Package & Tooling: Recommendations for standard project layouts, avoiding package-level state, functional options, embedding, and integrating gofmt, goimports, linters, and static analysis.
  • Use Case: Perform a code review of a legacy HTTP service to replace global state with dependency injection, add proper context timeouts, and enforce linting and formatting rules.

Quick Start

Use the golang-patterns skill to review my Go package and recommend idiomatic refactors, concurrency safeguards, and linter configurations.

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 sentinel error types?

Error handling in Go should use sentinel and custom error types, wrapping errors with context, and checking them with errors.Is and errors.As. This approach ensures predictable, maintainable application behavior.

What's the best way to prevent goroutine leaks when using worker pools in Go?

Preventing goroutine leaks in Go worker pools requires using context-based cancellation and timeouts alongside errgroup coordination. These concurrency patterns ensure stable background processing without resource exhaustion.

How do I structure my Go project to avoid package-level state and improve maintainability?

Structuring a Go project to avoid package-level state involves using standard project layouts and dependency injection. This pattern replaces global state to make functional requirements clear and code maintainable.

Why does my Go code review fail to catch interface design and zero-value usage issues?

Go code reviews often miss interface design and zero-value usage issues without idiomatic patterns. Applying focused interfaces, accepting interfaces, and returning structs ensures robust, predictable application architecture.

Can I use functional options and embedding when designing Go packages?

Yes, you can use functional options and embedding when designing Go packages. These idiomatic patterns provide flexible configuration and composition while maintaining clear, standard project layouts.

How do I integrate Go linters and static analysis into my codebase refactoring workflow?

Integrating Go linters and static analysis into a refactoring workflow involves configuring gofmt, goimports, and linters. This enforces consistent style and formatting rules across your repository.