golang-design-patterns

Design Go APIs with functional options and error handling patterns.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-design-patterns-samber
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-design-patterns
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-design-patterns
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-design-patterns-samber

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle to build maintainable, production-ready code with consistent patterns. This Skill codifies idiomatic design patterns in Go—functional options, constructors, error flow, resource management, graceful shutdown, architecture decisions, and deployment readiness—so teams can write predictable, evolvable code.

Core Features & Use Cases

  • Functional options for flexible constructors and stable APIs that can evolve without breaking changes.
  • Guidance on avoiding init() and mutable globals to improve testability and reliability.
  • Patterns for error handling, lifecycle management, and deterministic behavior in production systems.
  • Architecture guidance with pragmatic examples for library code, services, and CLIs.

Quick Start

Implement a small struct with a functional options constructor and a runnable example to illustrate the pattern.

Frequently Asked Questions about golang-design-patterns

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

FAQPage Schema
How do I use functional options in Go to build flexible constructors?

Functional options in Go allow you to build flexible constructors by passing configuration functions to a struct initializer, enabling stable APIs that evolve without breaking changes. This pattern provides explicit defaults and improves testability.

Why should I avoid init() and mutable globals when writing Go services?

Avoiding init() and mutable globals in Go services improves testability and reliability by preventing hidden side effects during package initialization. Explicit constructors ensure deterministic behavior and predictable lifecycle management in production systems.

What's the best way to handle graceful shutdown and resource management in Go?

The best way to handle graceful shutdown in Go involves explicit resource management patterns and careful error handling during lifecycle transitions. This ensures deterministic behavior and clean cleanup for production-ready CLIs and services.

Can I apply clean architecture guidance to Go library code and CLIs?

Yes, you can apply clean architecture guidance to Go library code and CLIs by organizing code with functional options, avoiding mutable globals, and enforcing explicit defaults. This approach ensures predictable and evolvable architecture decisions.

When do I need to start enums at 1 in Go, and what are the explicit defaults?

You should start enums at 1 in Go to reserve the zero value as an uninitialized state, which enforces explicit defaults and prevents accidental usage of unset configurations in production-ready code.

Does this Go design pattern guidance work for both libraries and production services?

Yes, this Go design pattern guidance works for libraries, CLIs, and production services by codifying idiomatic patterns like functional options, error flow management, and graceful shutdown to ensure consistent and maintainable code.