What are the trade-offs of using 'Functional Options' versus a 'Constructor Configuration Struct'?
Last updated
Functional options are functions like
func(*Server)applied in a variadic constructor. They give defaults, readable call sites, and let you add options without breaking callers, at the cost of boilerplate and discoverability.A config struct passes all settings as fields: simple, explicit, and visible, but telling "unset" from the zero value is awkward and it can grow cluttered.
Use a config struct for few stable settings. Use functional options for many optional, evolving settings or public library APIs.
- https://dev.to/gabrielanhaia/functional-options-vs-builder-vs-config-struct-in-go-pick-one-3i1c
- https://www.smarty.com/blog/functional-options-pattern-in-go-flexibility
- https://medium.com/@chaewonkong/functional-options-pattern-in-go-99ab386397ea
- https://www.reddit.com/r/golang/comments/1ejm6fm/do_you_really_prefer_functional_options_pattern/
- https://www.dennisokeeffe.com/blog/2025-11-16-interface-based-functional-options-in-golang