You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 21, 2022. It is now read-only.
I understand it's at very early stage, so just want to provide some feedback after my attempt to use it.
We uses similar API designed inspired by (this article)[https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis] in our team. This approach only works if the functional options takes exported type with exported fields. Otherwise, the constructor is completely not configurable.
Here is the patterns we ends up using, in case we want to keep the Type's field hidden:
type Options func(*Opt)
type Opt struct {
ConfigurableField1 type
ConfigurableField2 type
}
type SomeType struct {
field1 type
field2 type
}
func New(opts ...Options) *SomeType {
opt := Opt{
// defaults
}
for _, optFunc := range opts {
optFunc(&opt)
}
return &SomeType {
field1: opt.ConfigurableField1,
field2: opt.ConfigurableField2,
}
}
This is a great library and I hope the V4 reaches a stable state soon.
The text was updated successfully, but these errors were encountered:
I understand it's at very early stage, so just want to provide some feedback after my attempt to use it.
We uses similar API designed inspired by (this article)[https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis] in our team. This approach only works if the functional options takes exported type with exported fields. Otherwise, the constructor is completely not configurable.
Here is the patterns we ends up using, in case we want to keep the Type's field hidden:
This is a great library and I hope the V4 reaches a stable state soon.
The text was updated successfully, but these errors were encountered: