yet another style for optional args in go

func NewFoo(options ...FooOption) *Foo {
// ... implementation
}

func CallNewFoo() *Foo {
return NewFoo(WithBoolOption(), WithIntOption(42))
}
func NewFooStruct(config FooConfig) *Foo {
// ... implementation
}

func CallNewFooStruct() *Foo {
return NewFooStruct(FooConfig{BoolOption: true, IntOption: 42})
}
type NewFoo struct {
BoolOption bool,
IntOption int,
// ...
}
func (nf NewFoo) Create() *Foo {
// make a new *Foo and return it
}
myFoo := NewFoo{ BoolOption: true, IntOption: 42 }.Create()
result := ComputeComplex{ OptA: 12, OptD: 3, OptJ: "ack" }.Exec()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store