fake-sms/internal/storm/option.go

52 lines
783 B
Go
Raw Permalink Normal View History

2020-12-21 15:56:56 +01:00
package storm
type Option struct {
Path string
Objects []interface{}
ReIndex bool
Init bool
}
type OptionFunc func(*Option)
func DefaultOption() *Option {
return MergeOption(
&Option{},
WithPath("data.db"),
WithInit(true),
WithReIndex(true),
)
}
func MergeOption(opt *Option, funcs ...OptionFunc) *Option {
for _, fn := range funcs {
fn(opt)
}
return opt
}
func WithPath(path string) OptionFunc {
return func(opt *Option) {
opt.Path = path
}
}
func WithReIndex(reindex bool) OptionFunc {
return func(opt *Option) {
opt.ReIndex = reindex
}
}
func WithInit(init bool) OptionFunc {
return func(opt *Option) {
opt.Init = init
}
}
func WithObjects(objects ...interface{}) OptionFunc {
return func(opt *Option) {
opt.Objects = objects
}
}