golang-design-patterns

Apply idiomatic Go design patterns for construction, error flow, and resilience.

2|Updated Feb 12, 2024
One-click install
npx skills add https://github.com/adibfirman/dotfiles --skill golang-design-patterns-adibfirman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-design-patterns
Source: https://github.com/adibfirman/dotfiles/tree/main/claude/.claude/skills/technical/golang/golang-design-patterns
Command: npx skills add https://github.com/adibfirman/dotfiles --skill golang-design-patterns-adibfirman

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you choose and implement idiomatic, production-ready Go design patterns without adding unnecessary complexity, especially around construction, error flow, resource lifecycle, graceful shutdown, resilience, and dependency injection.

Core Features & Use Cases

  • Constructor and configuration design: Prefer functional options to evolve APIs safely, with validation errors surfaced at construction time.
  • Error handling and control flow: Handle error cases first with early returns and use panic only for bugs/invariant violations.
  • Resource lifecycle discipline: Enforce cleanup practices like deferring Close() immediately after opening and prefer runtime.AddCleanup over runtime.SetFinalizer.
  • Architecture guidance with guardrails: Right-size architecture, keep domain logic pure, and push for explicitness over implicit behavior.
  • Resilience and limits: Require timeouts on external calls, apply bounded resources, and implement retry logic that respects context cancellation.
  • Data handling and performance: Use streaming/iterators for large data, avoid repeated allocations, and compile regexps once at package scope.

Quick Start

Use the golang-design-patterns skill to review your Go service design decisions and produce the smallest set of idiomatic patterns that match your specific problem and constraints.

Frequently Asked Questions about golang-design-patterns

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

FAQPage Schema
What's the best way to configure Go APIs using functional options?

Functional options in Go allow you to evolve APIs safely by passing configuration functions to a constructor, enabling validation errors to surface at construction time rather than during runtime execution.

How do I handle error flow and resource cleanup in production Go services?

Handle error flow in Go by checking errors first with early returns and using panic only for invariant violations, while enforcing resource cleanup by deferring Close() immediately after opening files or connections.

When do I need graceful shutdown and context-aware retries in Golang?

You need graceful shutdown and context-aware retries in Go when building production systems that require timeouts on external calls, bounded resources, and retry logic that properly respects context cancellation to prevent resource leaks.

How do I avoid init() abuse and keep domain logic pure in Go?

Avoid init() abuse in Go by enforcing validation at construction time and keeping domain logic pure through explicit dependencies, ensuring architecture right-sizing and pushing for explicitness over implicit behavior.

Does this approach to Go design patterns work for large data streaming and performance optimization?

Yes, this Go design pattern approach handles large data by using streaming iterators, avoiding repeated allocations, and compiling regular expressions once at package scope to optimize performance and cap resources effectively.