Reusable and type-safe options for Go APIs
https://derekchiang.com/posts/reusable-and-type-safe-options-for-go-apis/Background In this blog post, I would like to describe an extension to the popular “functional options” pattern that has been described by people like Rob Pike and Dave Cheney. I recommend reading one of these articles if you are unfamiliar with this pattern, as it’s very useful in practice.
The problem To see the limitations of the pattern, consider the etcd v3 client. Specifically, let’s look at the KV interface which exposes APIs for putting and getting key-value pairs.