golang-design-patterns

Select idiomatic Go design patterns for constructors, error flow, and architecture.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-design-patterns-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-design-patterns
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-design-patterns
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-design-patterns-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you choose idiomatic Go design patterns and architecture choices that keep code simple, testable, and production-ready.

Core Features & Use Cases

  • Constructor Design: Use functional options for evolving APIs and validation-friendly configuration.
  • Go Best Practices: Avoid init, handle errors early, use defer immediately, and prefer explicit defaults over hidden magic.
  • Architecture Guidance: Decide when to use clean architecture, hexagonal architecture, DDD, streaming, retries, graceful shutdown, and bounded resource pools.
  • Use Case: Apply it when building or reviewing a Go service and you want the smallest correct pattern for the problem instead of over-engineering.

Quick Start

Use the golang-design-patterns skill to review my Go code and recommend the most idiomatic, production-ready pattern for this design problem.

Frequently Asked Questions about golang-design-patterns

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

FAQPage Schema
How do I implement functional options in Golang for evolving APIs?

Implement graceful shutdown in Go services by applying explicit initialization, timeout-aware external calls, and immediate defer for cleanup. This pattern ensures bounded resource pools drain correctly and prevents data loss during termination without relying on hidden init functions.

When should I use clean architecture or hexagonal architecture in a Go service?

Apply clean architecture or hexagonal architecture in Go when you need pure domain boundaries without unnecessary abstraction. Choose these patterns to keep code testable and production-ready, ensuring domain-friendly layering and explicit separation between external concerns and core logic.

What is the best way to handle resource management and bounded pools in Go?

The best way to handle resource management in Go is using bounded pools with explicit initialization and immediate defer for cleanup. This approach prevents resource leaks, maintains simple code structure, and ensures production-ready behavior under high concurrency without over-engineering.

How do I structure error flow and avoid init in Go code reviews?

Structure Go error flow by handling errors early and avoiding init functions entirely. Prefer explicit initialization and validated constructors over hidden magic, ensuring that error paths are visible, testable, and maintain predictable behavior throughout the service lifecycle.

Do I need clean architecture for simple Go APIs or does it add unnecessary abstraction?

You do not need clean architecture for simple Go APIs if it introduces unnecessary abstraction. Select the smallest correct pattern for the problem, preferring explicit defaults and pure domain boundaries that maintain testability without over-engineering the service layering.