mirror of
https://github.com/jimeh/go-golden.git
synced 2026-02-19 11:16:47 +00:00
feat(options): add optional Options arguments to New() function (#14)
Enables simpler creation of custom *Golden instances, as you can just pass in the custom values to New(), rather than modifying fields after increating the Golden instance.
This commit is contained in:
43
options.go
Normal file
43
options.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package golden
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// Option is a function that modifies a Golden instance.
|
||||
type Option func(*Golden)
|
||||
|
||||
// WithDirMode sets the directory mode for a Golden instance.
|
||||
func WithDirMode(mode os.FileMode) Option {
|
||||
return func(g *Golden) {
|
||||
g.DirMode = mode
|
||||
}
|
||||
}
|
||||
|
||||
// WithFileMode sets the file mode for a Golden instance.
|
||||
func WithFileMode(mode os.FileMode) Option {
|
||||
return func(g *Golden) {
|
||||
g.FileMode = mode
|
||||
}
|
||||
}
|
||||
|
||||
// WithSuffix sets the file suffix for a Golden instance.
|
||||
func WithSuffix(suffix string) Option {
|
||||
return func(g *Golden) {
|
||||
g.Suffix = suffix
|
||||
}
|
||||
}
|
||||
|
||||
// WithDirname sets the directory name for a Golden instance.
|
||||
func WithDirname(dirname string) Option {
|
||||
return func(g *Golden) {
|
||||
g.Dirname = dirname
|
||||
}
|
||||
}
|
||||
|
||||
// WithUpdateFunc sets the update function for a Golden instance.
|
||||
func WithUpdateFunc(updateFunc UpdateFunc) Option {
|
||||
return func(g *Golden) {
|
||||
g.UpdateFunc = updateFunc
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user