
Go Functional Options
This teaches Claude the functional options pattern for Go constructors, the approach where you pass variadic Option types instead of sprawling parameter lists. It's well suited for any New* function with three or more optional parameters, or APIs that might grow over time. The skill covers the full implementation (unexported options struct, Option interface with unexported apply method, With* constructors) and includes a comparison table against config structs so you know when to use which. It's opinionated about preferring interfaces over closures for testability, and the examples are lifted from Uber's style guide. Good reference material if you're tired of constructors that take eight booleans.
- skills.sh installs
- 1.3K
- GitHub stars
- 193
- last updated
- Aug 21, 2026
Install
$ npx -y skills add cxuu/golang-skills --skill go-functional-options --agent claude-codeInstalls into .claude/skills of the current project.
Files
Functional Options Pattern
Functional options is a pattern where you declare an opaque Option type that records information in an internal struct. The constructor accepts a variadic number of these options and applies them to configure the result.
Resource Routing
references/OPTIONS-VS-STRUCTS.md- Read when choosing between config structs and functional options, implementing the full interface-based option pattern, or evaluating hybrid constructor APIs.
When to Use
Use functional options when:
- 3+ optional arguments on constructors or public APIs
- Extensible APIs that may gain new options over time
- Clean caller experience is important (no need to pass defaults)
The Pattern
Core Components
- Unexported
optionsstruct - holds all configuration - Exported
Optioninterface - with unexportedapplymethod - Option types - implement the interface
With*constructors - create options
Option Interface
type Option interface {
apply(*options)
}
The unexported apply method ensures only options from this package can be used.
Comparison: Functional Options vs Config Struct
Sponsors
Details
- Repository
- github.com/cxuu/golang-skills
- Categories
- Go, Design & UI/UX
- First seen
- May 16, 2026
More from cxuu/golang-skills
All 20- Go Control Flow1.3K
- Go Logging1.1K
- Go Functions1.1K
- Go Generics1.1K
- Go Declarations1.1K
- Go Code Review1.8K
- Go Testing1.4K
- Go Error Handling1.3K
- Go Linting1.3K
- Go Concurrency1.3K
- Go Interfaces1.3K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
- Go Data Structures1.3K