go-functional-options

Generate Go functional options pattern code with With* constructors and an Option interface.

139|17|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/cxuu/golang-skills --skill go-functional-options
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-functional-options
Source: https://github.com/cxuu/golang-skills/tree/main/skills/go-functional-options
Command: npx skills add https://github.com/cxuu/golang-skills --skill go-functional-options

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

API constructors with many optional parameters lead to brittle and hard-to-use code. The functional options pattern provides a flexible, scalable approach by decoupling configuration from constructors.

Core Features & Use Cases

  • Unexported internal options struct to hold configuration
  • Exported Option interface with an unexported apply method
  • With* constructors to compose configuration
  • Use cases include API constructors with 3+ optional parameters and future extensibility

Quick Start

Instantiate the API with default options and apply any number of With* options to customize behavior.

Frequently Asked Questions about go-functional-options

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

FAQPage Schema
How do I handle optional parameters in a Go API constructor?

Optional parameters in a Go API constructor are handled using the functional options pattern, which decouples configuration from the constructor by applying With* functions to a defaultable Open function.

What is the functional options pattern in Go API design?

The functional options pattern in Go API design is a technique using an unexported options struct and an exported Option interface with an unexported apply method to provide flexible, scalable configuration.

When should I use functional options for Go constructors?

You should use functional options for Go constructors when an API requires three or more optional parameters, or when you need future extensibility without breaking existing callers.

How do I create configurable Go constructors with With* functions?

Configurable Go constructors are created by defining With* functions that compose configuration, then passing them to an exported Open function that applies them over an unexported default options struct.

What's the best way to design flexible Go APIs for future extensibility?

Designing flexible Go APIs for future extensibility is best achieved with the functional options pattern, allowing clean caller experience by adding new With* constructors without modifying existing function signatures.