Last active
March 28, 2025 02:10
-
-
Save patrickhuber/b7d570b0741f31982fb02f1698cd305e to your computer and use it in GitHub Desktop.
Interface Options with Reuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type option map[string]any | |
const transformerKey string = "transformer" | |
func (option) transformerOption() {} | |
type TransformerOption interface { | |
transformerOption() | |
} | |
type Transformer interface{ | |
Transform(any) (any, error) | |
} | |
func WithTransformer(transformer Transformer) option { | |
return option{ | |
transformerKey: transformer, | |
} | |
} | |
type ProviderOption interface { | |
providerOption() | |
} | |
func (option) providerOption() {} | |
func WithProvider() ProviderOption { | |
return option{} | |
} | |
func NewThing(options ...ProviderOption) { | |
} | |
func UseThing() { | |
NewThing(WithTransformer(nil), WithProvider()) | |
} | |
type OtherOption interface { | |
otherOption() | |
} | |
func (option) otherOption() {} | |
func WithOther() OtherOption { | |
return option{} | |
} | |
func NewOther(options ...OtherOption) { | |
} | |
func UseOther() { | |
NewOther(WithTransformer(nil), WithProvider(), WithOther()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment