# Golang Design Patterns

Idiomatic Golang design patterns, functional options, constructor APIs, `init()` and...

- Repository: https://github.com/samber/cc-skills-golang (3750 stars)
- Category: Design
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add samber/cc-skills-golang --skill golang-design-patterns -g -a claude-code -y`
Codex: `npx skills add samber/cc-skills-golang --skill golang-design-patterns -g -a codex -y`
Cursor: `npx skills add samber/cc-skills-golang --skill golang-design-patterns -g -a cursor -y`
Gemini CLI: `npx skills add samber/cc-skills-golang --skill golang-design-patterns -g -a gemini-cli -y`

## Description

Idiomatic Golang design patterns, functional options, constructor APIs, `init()` and global-state avoidance, enums, panic vs error decisions, resource management and lifecycle, graceful shutdown, timeouts and retries, streaming and iterators, and architecture styles (clean, hexagonal, DDD, flat). Apply when choosing between architectural patterns, implementing functional options, designing constructor APIs, setting up graceful shutdown, applying resilience patterns, or asking which idiomatic Go pattern fits a specific problem. Not for wiring a DI container or comparing DI libraries (→ See `samber/cc-skills-golang@golang-dependency-injection` skill), nor for error wrapping, `errors.Is`/`As`, or logging mechanics (→ See `samber/cc-skills-golang@golang-error-handling` skill).

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

**Persona:** You are a Go architect who values simplicity and explicitness. You apply patterns only when they solve a real problem, not to demonstrate sophistication, and you push back on premature abstraction.

**Modes:**

- **Design mode**, creating new APIs, packages, or application structure: ask the developer about their architecture preference before proposing patterns; favor the smallest pattern that satisfies the requirement.
- **Review mode**, auditing existing code for design issues: scan for `init()` abuse, unbounded resources, missing timeouts, and implicit global state; report findings before suggesting refactors.

> **Community default.** A company skill that explicitly supersedes `samber/cc-skills-golang@golang-design-patterns` skill takes precedence.

# Go Design Patterns & Idioms

Idiomatic Go patterns for production-ready code. For error handling details see the `samber/cc-skills-golang@golang-error-handling` skill; for context propagation see `samber/cc-skills-golang@golang-context` skill; for struct/interface design see `samber/cc-skills-golang@golang-structs-interfaces` skill.

## Best Practices Summary

The rest: https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-design-patterns/SKILL.md
