forked from ostafen/clover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
49 lines (43 loc) · 1001 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package clover
// Config contains clover configuration parameters
type Config struct {
InMemory bool
Storage StorageEngine
}
func defaultConfig() *Config {
return &Config{
InMemory: false,
Storage: newDefaultStorageImpl(),
}
}
func (c *Config) applyOptions(opts []Option) (*Config, error) {
for _, opt := range opts {
if err := opt(c); err != nil {
return nil, err
}
}
return c, nil
}
// Option is a function that takes a config struct and modifies it
type Option func(c *Config) error
// InMemoryMode allows to enable/disable in-memory mode.
func InMemoryMode(enable bool) Option {
return func(c *Config) error {
if enable {
c.Storage = newMemStorageEngine()
} else {
c.Storage = newDefaultStorageImpl()
}
c.InMemory = enable
return nil
}
}
// WithStorageEngine allows to specify a custom storage engine.
func WithStorageEngine(engine StorageEngine) Option {
return func(c *Config) error {
if engine != nil {
c.Storage = engine
}
return nil
}
}