golang-patterns

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

1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/khetansarvesh/ai_skills_repo --skill golang-patterns-khetansarvesh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/khetansarvesh/ai_skills_repo/tree/main/skills/golang-patterns
Command: npx skills add https://github.com/khetansarvesh/ai_skills_repo --skill golang-patterns-khetansarvesh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you avoid common Go mistakes and design code that is readable, maintainable, and performant by applying proven idioms and conventions for errors, concurrency, interfaces, packages, and memory usage.

Core Features & Use Cases

  • Idiomatic API and type design: Make the zero value useful, accept interfaces, return concrete types, and design clear package/struct boundaries.
  • Robust error handling: Wrap errors with context, define domain-specific/sentinel errors, and use errors.Is/errors.As without ignoring failures.
  • Safe concurrency patterns: Use worker pools, context-aware cancellation/timeouts, errgroup coordination, and techniques that prevent goroutine leaks.
  • Performance-aware Go: Preallocate slices when sizes are known, use sync.Pool for frequent allocations, and avoid inefficient string concatenation in loops.
  • Practical workflow support: Apply gofmt/goimports and lint/test commands as part of a repeatable Go development process.

Quick Start

Ask the AI to rewrite your Go function to follow idiomatic patterns for error wrapping, interface usage, and concurrency safety, using your code snippet and specifying whether it runs as an HTTP handler, background worker, or library.

Frequently Asked Questions about golang-patterns

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

FAQPage Schema
How do I wrap errors with context in Go without losing the original error type?

Wrap errors with context in Go by using fmt.Errorf with the %w verb, then inspect wrapped errors using errors.Is and errors.As to preserve domain-specific sentinel error matching across package boundaries.

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

Prevent goroutine leaks in Go worker pools by using context-aware cancellation, coordinating concurrent operations with errgroup, and ensuring all goroutines exit cleanly when context signals are received or work is complete.

How do I design Go interfaces and structs for better zero-value usability?

Design Go structs for zero-value usability by making default fields immediately functional, accepting interfaces for parameters while returning concrete types, and defining clear package boundaries for maintainable API consumers.

Why does my Go service have high memory allocations and how can I optimize performance?

Optimize Go service performance by preallocating slices when sizes are known, using sync.Pool for frequent allocations, and avoiding inefficient string concatenation within loops to reduce garbage collection pressure.

Can I use this to refactor an existing HTTP handler into idiomatic Go code?

Yes, you can refactor existing HTTP handlers, background workers, or library code by providing the snippet and execution context to apply idiomatic patterns for error handling, concurrency, and interface usage.

What Go linting and formatting commands should I run to maintain code quality?

Maintain Go code quality by running gofmt or goimports for formatting, combined with lint and test commands, to create a repeatable development process that enforces idiomatic conventions and correctness.