Function Option TL;DR
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
package entity | |
type Entity struct { | |
fieldOne string | |
} | |
type Option func(e *Entity) | |
func FieldOne(fieldOne string) Option { | |
return func(e *Entity) { | |
e.fieldOne = fieldOne | |
} | |
} | |
func (e *Entity) WithOptions(options ...Option) { | |
for _, option := range options { | |
option(e) | |
} | |
} | |
//Usage: | |
// | |
//e := &Entity{} | |
//e.WithOptions( | |
// FieldOne("field one's value"), | |
//) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment