Skip to main content
100%

See the blog post: https://derekchiang.com/posts/reusable-and-type-safe-options-for-go-apis

✓ Published0🌍 Public
Aallyraza
Last edited Oct 23, 2017
Created on May 13, 2018

This example demonstrates a type-safe functional options pattern for Go APIs, using the `Get` and `Delete` functions to apply reusable option structs like `WithPrefix` and `WithRev`. The `GetOption` and `DeleteOption` interfaces enforce compile-time compatibility, allowing `WithPrefix` to work across both operations while rejecting mismatched options like passing `WithRev` to `Delete`. The code prints the assembled option structs via `fmt.Printf` in `main`, showing how each option mutates its respective configuration.

AI-generated description

Similar vizzes