NatsIO which is a pretty major application has this
https://www.javadoc.io/doc/io.nats/jnats/2.0.0/io/nats/client/Options.Builder.html
This is a pretty good “tutorial” - and I think you can see how it can be
applied to parameters or instance creation (e.g. the server instance). see
I'm not familiar with the Builder pattern. Could you provide a good example
of its use in a Go package?
On Mon, 25 May 2020, 06:25 robert engels, wrote:
> I think the Builder pattern is easier than this, and it retains the
> property of both ‘config struct’ and ‘multiple args’ versions that the
Thanks Robert for the nice idea.
Using builder pattern to set options didn't come to my mind. Looks really
clean.
On Mon, 25 May, 2020, 10:55 AM robert engels, wrote:
> I think the Builder pattern is easier than this, and it retains the
> property of both ‘config struct’ and ‘multiple args’
I think the Builder pattern is easier than this, and it retains the property of
both ‘config struct’ and ‘multiple args’ versions that the implementation can
re-order and validate option in aggregate easier - but most of all is doesn’t
pollute that package with top-level public functions. The
Thanks James for your response and the amazing posts.
On Mon, May 25, 2020 at 9:01 AM James wrote:
> This reminds me of functional options which I think are used quite widely
> for this purpose.
>
> See
> https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
> and
>
This reminds me of functional options which I think are used quite widely
for this purpose.
See https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
and
https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md
On Mon, 25 May 2020 at 14:57, Amarjeet Anand
Is it acceptable to make the optional parameter as varargs?
I wrote code in my package like ...
package backoff
func New(options ...Options) *backOff {
backOff := defaultBackOff()
if len(options) == 0 {
return backOff
}
// override default values
if len(options) > 1 {