diff --git a/examples/animal.go b/examples/animal.go new file mode 100644 index 0000000..b047113 --- /dev/null +++ b/examples/animal.go @@ -0,0 +1,9 @@ +package animal + +//go:generate go run github.com/andreykaipov/funcopgen -type=Animal -prefix=With -factory -unexported + +type Animal struct { + Surname string + Color string + cute bool +} diff --git a/examples/zz_generated.animal_funcop.go b/examples/zz_generated.animal_funcop.go new file mode 100644 index 0000000..7188fe9 --- /dev/null +++ b/examples/zz_generated.animal_funcop.go @@ -0,0 +1,35 @@ +// This file has been automatically generated. Don't edit it. + +package animal + +import () + +type Option func(*Animal) + +func NewAnimal(opts ...Option) *Animal { + o := &Animal{} + + for _, opt := range opts { + opt(o) + } + + return o +} + +func WithColor(x string) Option { + return func(o *Animal) { + o.Color = x + } +} + +func WithSurname(x string) Option { + return func(o *Animal) { + o.Surname = x + } +} + +func WithCute(x bool) Option { + return func(o *Animal) { + o.cute = x + } +}