summaryrefslogtreecommitdiff
path: root/plugins/kv
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-21 13:25:36 +0300
committerValery Piashchynski <[email protected]>2021-01-21 13:25:36 +0300
commit7da6c78449776e1f3c6716250bca0b712a0423a4 (patch)
treef3512de66aca2bba408485a0ea2fc936c0e4fb9b /plugins/kv
parent0ff05b2732b4fd0783f959c94c54d7e39169f979 (diff)
Uniform all configs
Add debug server Check nil's for all plugin intialization
Diffstat (limited to 'plugins/kv')
-rw-r--r--plugins/kv/boltdb/config.go23
-rw-r--r--plugins/kv/boltdb/plugin.go8
-rw-r--r--plugins/kv/memcached/config.go4
-rw-r--r--plugins/kv/memcached/plugin.go8
-rw-r--r--plugins/kv/memory/config.go7
-rw-r--r--plugins/kv/memory/plugin.go8
-rw-r--r--plugins/kv/memory/plugin_unit_test.go1
7 files changed, 41 insertions, 18 deletions
diff --git a/plugins/kv/boltdb/config.go b/plugins/kv/boltdb/config.go
index ea0e3375..ebe73c25 100644
--- a/plugins/kv/boltdb/config.go
+++ b/plugins/kv/boltdb/config.go
@@ -16,9 +16,22 @@ type Config struct {
// InitDefaults initializes default values for the boltdb
func (s *Config) InitDefaults() {
- s.Dir = "." // current dir
- s.Bucket = "rr" // default bucket name
- s.File = "rr.db" // default file name
- s.Permissions = 0777 // free for all
- s.Interval = 60 // default is 60 seconds timeout
+ if s.Dir == "" {
+ s.Dir = "." // current dir
+ }
+ if s.Bucket == "" {
+ s.Bucket = "rr" // default bucket name
+ }
+
+ if s.File == "" {
+ s.File = "rr.db" // default file name
+ }
+
+ if s.Permissions == 0 {
+ s.Permissions = 777 // free for all
+ }
+
+ if s.Interval == 0 {
+ s.Interval = 60 // default is 60 seconds timeout
+ }
}
diff --git a/plugins/kv/boltdb/plugin.go b/plugins/kv/boltdb/plugin.go
index 683d6fc5..1e3d2c34 100644
--- a/plugins/kv/boltdb/plugin.go
+++ b/plugins/kv/boltdb/plugin.go
@@ -42,15 +42,19 @@ type Plugin struct {
func (s *Plugin) Init(log logger.Logger, cfg config.Configurer) error {
const op = errors.Op("boltdb_plugin_init")
- s.cfg = &Config{}
- s.cfg.InitDefaults()
+ if !cfg.Has(PluginName) {
+ return errors.E(op, errors.Disabled)
+ }
err := cfg.UnmarshalKey(PluginName, &s.cfg)
if err != nil {
return errors.E(op, errors.Disabled, err)
}
+ // add default values
+ s.cfg.InitDefaults()
+
// set the logger
s.log = log
diff --git a/plugins/kv/memcached/config.go b/plugins/kv/memcached/config.go
index 62f29ef2..7aad53b6 100644
--- a/plugins/kv/memcached/config.go
+++ b/plugins/kv/memcached/config.go
@@ -6,5 +6,7 @@ type Config struct {
}
func (s *Config) InitDefaults() {
- s.Addr = []string{"localhost:11211"} // default url for memcached // init logger
+ if s.Addr == nil {
+ s.Addr = []string{"localhost:11211"} // default url for memcached
+ }
}
diff --git a/plugins/kv/memcached/plugin.go b/plugins/kv/memcached/plugin.go
index e8b05567..181b8a49 100644
--- a/plugins/kv/memcached/plugin.go
+++ b/plugins/kv/memcached/plugin.go
@@ -36,12 +36,16 @@ func NewMemcachedClient(url string) kv.Storage {
func (s *Plugin) Init(log logger.Logger, cfg config.Configurer) error {
const op = errors.Op("memcached_plugin_init")
- s.cfg = &Config{}
- s.cfg.InitDefaults()
+ if !cfg.Has(PluginName) {
+ return errors.E(op, errors.Disabled)
+ }
err := cfg.UnmarshalKey(PluginName, &s.cfg)
if err != nil {
return errors.E(op, err)
}
+
+ s.cfg.InitDefaults()
+
s.log = log
return nil
}
diff --git a/plugins/kv/memory/config.go b/plugins/kv/memory/config.go
index 0816f734..e51d09c5 100644
--- a/plugins/kv/memory/config.go
+++ b/plugins/kv/memory/config.go
@@ -2,14 +2,13 @@ package memory
// Config is default config for the in-memory driver
type Config struct {
- // Enabled or disabled (true or false)
- Enabled bool
// Interval for the check
Interval int
}
// InitDefaults by default driver is turned off
func (c *Config) InitDefaults() {
- c.Enabled = false
- c.Interval = 60 // seconds
+ if c.Interval == 0 {
+ c.Interval = 60 // seconds
+ }
}
diff --git a/plugins/kv/memory/plugin.go b/plugins/kv/memory/plugin.go
index ddcf88a9..4201a1c0 100644
--- a/plugins/kv/memory/plugin.go
+++ b/plugins/kv/memory/plugin.go
@@ -25,13 +25,15 @@ type Plugin struct {
func (s *Plugin) Init(cfg config.Configurer, log logger.Logger) error {
const op = errors.Op("in_memory_plugin_init")
- s.cfg = &Config{}
- s.cfg.InitDefaults()
-
+ if !cfg.Has(PluginName) {
+ return errors.E(op, errors.Disabled)
+ }
err := cfg.UnmarshalKey(PluginName, &s.cfg)
if err != nil {
return errors.E(op, err)
}
+
+ s.cfg.InitDefaults()
s.log = log
s.stop = make(chan struct{}, 1)
diff --git a/plugins/kv/memory/plugin_unit_test.go b/plugins/kv/memory/plugin_unit_test.go
index 6daa0795..1965a696 100644
--- a/plugins/kv/memory/plugin_unit_test.go
+++ b/plugins/kv/memory/plugin_unit_test.go
@@ -17,7 +17,6 @@ func initStorage() kv.Storage {
stop: make(chan struct{}),
}
p.cfg = &Config{
- Enabled: true,
Interval: 1,
}