Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
andreykaipov committed Apr 22, 2021
1 parent 08f4225 commit 7d14bc4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/animal.go
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 35 additions & 0 deletions examples/zz_generated.animal_funcop.go
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 7d14bc4

Please sign in to comment.