# golang-design-patterns

> Claude/Codex skill by [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars · Updated 2026-10-23

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).

Tags: agent, agent-skills, ai, antigravity, claude, claude-code, code, codex, coding, copilot, cursor, gemini, gemini-cli-extension, openclaw, opencode, plugin, skills, skillsmp, vibe-coding

## Install

```sh
git clone https://github.com/samber/cc-skills-golang /tmp/cc-skills-golang && ln -s /tmp/cc-skills-golang/skills/golang-design-patterns ~/.claude/skills/golang-design-patterns
```

## From README

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 Constructors SHOULD use functional options — they scale better as APIs evolve (one function per option, no breaking changes) Functional options MUST return an error if validation can fail — catch bad config at construction, not at runtime Avoid init() — runs implicitly, cannot return errors, makes testing unpredictable.

## Links

- HTML page: https://omgskills.com/library/samber/cc-skills-golang/golang-design-patterns/
- GitHub: https://github.com/samber/cc-skills-golang
- Author: [@samber](https://omgskills.com/library/samber/index.md)

## More from this repo

- [golang-benchmark](https://omgskills.com/library/samber/cc-skills-golang/golang-benchmark/index.md) — Golang benchmarking, profiling, and performance measurement.
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars
- [golang-cli](https://omgskills.com/library/samber/cc-skills-golang/golang-cli/index.md) — Golang CLI application development.
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars
- [golang-code-style](https://omgskills.com/library/samber/cc-skills-golang/golang-code-style/index.md) — Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments...
   - [@samber](https://omgskills.com/library/samber/index.md) · 3.7k stars
