
Go Functional Options
Go constructor pattern for optional configuration via an unexported options struct and With* functions.
- skills.sh installs
- 1.3K
- GitHub stars
- 196
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers the functional options pattern: an unexported
optionsstruct, an exportedOptioninterface, andWith*constructors - Includes a comparison table against config structs and a rationale for the interface approach over bare closures
- Enforces an unexported
applymethod so only options defined in the package can be passed to the constructor - Designed for Go constructors with 3 or more optional parameters or public APIs expected to gain options over time
Install
$ npx -y skills add cxuu/golang-skills --skill go-functional-options -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
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
Details
- Repository
- github.com/cxuu/golang-skills
- Category
- Go
- First seen
- May 16, 2026
More from cxuu/golang-skills
All 20- Go Data Structures1.3K
- 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.4K
- Go Concurrency1.4K
- Go Linting1.4K
- Go Interfaces1.4K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
Similar to Go Functional Options
More Go
golang-design-patternssamber/cc-skills-golang44.3K installsIdiomatic Go design patterns covering constructors, error flow, lifecycle, and architecture choices for production code.
go-functionscxuu/golang-skills1.1K installsGo function design rules covering file ordering, signature wrapping, interface parameters, and Printf-style naming.
go-genericscxuu/golang-skills1.1K installsConcrete guidance for deciding when Go generics pay off, with constraint and type-alias rules and common pitfalls.
golang-structs-interfacessamber/cc-skills-golang41.7K installsGo struct and interface design guide covering composition, embedding, type assertions, and pointer vs value receivers.
factory-patternpatternsdev/skills658 installsConcise JavaScript guide to factory functions that create objects without the new keyword, with explicit tradeoffs.