golang-patterns

Provide idiomatic Go patterns for writing, reviewing, and refactoring services and libraries.

905|126|Updated Jan 27, 2023
One-click install
npx skills add https://github.com/carrot-hu23/dst-admin-go --skill golang-patterns-carrot-hu23
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/carrot-hu23/dst-admin-go/tree/main/.claude/skills/golang-patterns
Command: npx skills add https://github.com/carrot-hu23/dst-admin-go --skill golang-patterns-carrot-hu23

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many Go projects suffer from inconsistent idioms, fragile concurrency, poor error handling, and unclear package boundaries; this Skill consolidates proven patterns and best practices to make Go code more readable, reliable, and maintainable.

Core Features & Use Cases

  • Simplicity and Clarity: Guidance for favoring simple, obvious implementations over clever constructs.
  • Error Handling & Types: Patterns for wrapping, classifying, and checking errors with examples.
  • Concurrency & Cancellation: Worker pools, context-based cancellation, errgroup usage, and strategies to avoid goroutine leaks.
  • Package and API Design: Recommendations for interface placement, package layout, and avoiding global state.
  • Tooling and Performance: Recommended Go tooling, linters, memory allocation avoidance, and performance idioms.
  • Use Case: Use when writing, reviewing, or refactoring services and libraries to enforce consistent idioms, improve safety, and reduce bugs.

Quick Start

Analyze this Go package and recommend idiomatic refactors to improve error handling, concurrency safety, and package organization.

Frequently Asked Questions about golang-patterns

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

FAQPage Schema
What are the best practices for Go error handling and wrapping?

Best practices for Go error handling involve wrapping errors with context, classifying error types, and checking them systematically to build reliable and maintainable applications.

How do I avoid goroutine leaks in concurrent Go code?

To avoid goroutine leaks in concurrent Go code, use context-based cancellation, implement worker pools correctly, and leverage errgroup for managing concurrent operations safely.

How do I structure Go packages for better maintainability?

Structure Go packages by defining clear interface placements, organizing package layout logically, and avoiding global state to improve code readability and maintainability.

What are the idiomatic patterns for Go memory allocation and performance?

Idiomatic Go performance patterns include avoiding unnecessary memory allocations, applying performance idioms, and using recommended Go tooling and linters to optimize production-grade projects.

When should I refactor my Go services for concurrency safety?

Refactor Go services for concurrency safety when you experience fragile concurrency, inconsistent idioms, or poor error handling, applying proven patterns to reduce bugs and enforce consistency.