-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08f4225
commit 7d14bc4
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |