Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cxuu avatar

Go Functional Options

  • 895 installs
  • 137 repo stars
  • Updated June 20, 2026
  • cxuu/golang-skills

go-functional-options is a Go agent skill that implements the functional options pattern for constructors with optional parameters for developers who need backward-compatible, extensible public APIs without long paramete

About

go-functional-options is a cxuu/golang-skills agent skill sourced from the Uber Go Style Guide and Google Style Guide that teaches the functional options pattern for Go constructors. Its decision framework recommends config structs for internal or test-only APIs, functional options for public APIs with 3+ optional parameters, and validation-friendly option application inside constructors. The pattern uses an unexported options struct, an exported Option interface with unexported apply methods, and With* helper functions applied variadically in New constructors. Developers reach for go-functional-options when designing Connect-style APIs, evolving library constructors, or choosing between functional options, config structs, and builder patterns in Go packages.

  • Decision framework based on Google and Uber style guides
  • Compares functional options pattern versus config structs across five decision criteria
  • Shows when to choose functional options for public APIs with 3+ options or growing configuration
  • Demonstrates config struct pattern for internal, test-only, or fixed-option use cases
  • Includes concrete good and bad code examples for both patterns

Go Functional Options by the numbers

  • 895 all-time installs (skills.sh)
  • +39 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #450 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cxuu/golang-skills --skill go-functional-options

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs895
repo stars137
Security audit3 / 3 scanners passed
Last updatedJune 20, 2026
Repositorycxuu/golang-skills

How do you design Go constructors with optional parameters?

Produce clean, extensible Go constructor APIs that support optional parameters without breaking changes.

Who is it for?

Go developers designing public library constructors with 3 or more optional settings that must evolve without breaking callers.

Skip if: Go developers with simple two-parameter constructors or configuration loaded entirely from YAML files where config structs are the wire format.

When should I use this skill?

User designs a Go New function with optional configuration, asks about functional options, or compares options versus config structs.

What you get

A Go constructor using variadic Option functions with defaults, With* helpers, and backward-compatible extension points.

  • Option interface and With* helpers
  • constructor with applied defaults

By the numbers

  • Decision framework targets public APIs with 3+ optional parameters
  • Sourced from Uber Go Style Guide and Google Style Guide references
  • Compares functional options against config structs and builder patterns

Files

SKILL.mdMarkdownGitHub ↗

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

1. Unexported `options` struct - holds all configuration 2. Exported `Option` interface - with unexported apply method 3. Option types - implement the interface 4. *`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

AspectFunctional OptionsConfig Struct
ExtensibilityAdd new With* functionsAdd new fields (may break)
DefaultsBuilt into constructorZero values or separate defaults
Caller experienceOnly specify what differsMust construct entire struct
TestabilityOptions are comparableStruct comparison
ComplexityMore boilerplateSimpler setup

Prefer Config Struct when: Fewer than 3 options, options rarely change, all options usually specified together, or internal APIs only.

Why Not Closures?

The interface approach is preferred over closure-only options because:

1. Testability - Options can be compared in tests and mocks 2. Debuggability - Options can implement fmt.Stringer 3. Flexibility - Options can implement additional interfaces 4. Visibility - Option types are visible in documentation

Quick Reference

// 1. Unexported options struct with defaults
type options struct {
    field1 Type1
    field2 Type2
}

// 2. Exported Option interface, unexported method
type Option interface {
    apply(*options)
}

// 3. Option type + apply + With* constructor
type field1Option Type1

func (o field1Option) apply(opts *options) { opts.field1 = Type1(o) }
func WithField1(v Type1) Option            { return field1Option(v) }

// 4. Constructor applies options over defaults
func New(required string, opts ...Option) (*Thing, error) {
    o := options{field1: defaultField1, field2: defaultField2}
    for _, opt := range opts {
        opt.apply(&o)
    }
    // ...
}

Checklist

  • [ ] options struct is unexported
  • [ ] Option interface has unexported apply method
  • [ ] Each option has a With* constructor
  • [ ] Defaults are set before applying options
  • [ ] Required parameters are separate from ...Option

Related Skills

  • Interface design: See go-interfaces when designing the Option interface or choosing between interface and closure approaches
  • Naming conventions: See go-naming when naming With* constructors, option types, or the unexported options struct
  • Function design: See go-functions when organizing constructors within a file or formatting variadic signatures
  • Documentation: See go-documentation when documenting Option types, With* functions, or constructor behavior

External Resources

Related skills

How it compares

Pick go-functional-options over config-struct skills when building extensible public Go library constructors expected to gain new knobs over time.

FAQ

When should go-functional-options be used?

go-functional-options recommends functional options for public Go APIs with 3+ optional parameters that must grow without breaking callers, and config structs for internal or serialization-bound configuration.

What structure does go-functional-options define?

go-functional-options defines an unexported options struct, an exported Option interface with an unexported apply method, With* helper functions, and a constructor that applies defaults then iterates variadic options.

Is Go Functional Options safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.