Functional options for friendly APIs
summary
Argues that using functional options — variadic configuration functions applied to a freshly created struct pointer — keeps defaults concise, avoids nil or empty sentinel values, and prevents callers retaining internal config. Shows concrete tools: option functions that mutate a server value, a TLS option that wraps the listener in TLS, and a speed returns closure pattern for parameterized options. Demonstrates the pattern on a real Go terminal/serial package where options are applied in order, errors abort and trigger cleanup, and the API becomes simpler and extensible.
AI-written summary · about
chapters (7)
- 0:00Start
- 1:01Features, features, features
- 3:26Many functions make light work
- 4:44Limited options
- 6:03Maybe adding indirection will help
- 10:30Functional options, cont
- 12:16Term (improved)








