guesstimate/server/internal/storm/option.go

52 lines
783 B
Go

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
}
}