diff options
Diffstat (limited to 'plugins/kv/plugin.go')
-rw-r--r-- | plugins/kv/plugin.go | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/plugins/kv/plugin.go b/plugins/kv/plugin.go index a1144b85..a2b36e3e 100644 --- a/plugins/kv/plugin.go +++ b/plugins/kv/plugin.go @@ -10,12 +10,13 @@ import ( "github.com/spiral/roadrunner/v2/plugins/logger" ) -// PluginName linked to the memory, boltdb, memcached, redis plugins. DO NOT change w/o sync. -const PluginName string = "kv" - const ( + // PluginName linked to the memory, boltdb, memcached, redis plugins. DO NOT change w/o sync. + PluginName string = "kv" // driver is the mandatory field which should present in every storage driver string = "driver" + // config key used to detect local configuration for the driver + cfg string = "config" ) // Plugin for the unified storage @@ -75,26 +76,45 @@ func (p *Plugin) Serve() chan error { continue } - // config key for the particular sub-driver kv.memcached - configKey := fmt.Sprintf("%s.%s", PluginName, k) + // config key for the particular sub-driver kv.memcached.config + configKey := fmt.Sprintf("%s.%s.%s", PluginName, k, cfg) // at this point we know, that driver field present in the configuration drName := v.(map[string]interface{})[driver] // driver name should be a string if drStr, ok := drName.(string); ok { - if _, ok := p.constructors[drStr]; !ok { - p.log.Warn("no constructors registered", "requested constructor", drStr, "registered", p.constructors) - continue + switch { + // local configuration section key + case p.cfgPlugin.Has(configKey): + if _, ok := p.constructors[drStr]; !ok { + p.log.Warn("no constructors registered", "requested constructor", drStr, "registered", p.constructors) + continue + } + + storage, err := p.constructors[drStr].KVConstruct(configKey) + if err != nil { + errCh <- errors.E(op, err) + return errCh + } + + // save the storage + p.storages[k] = storage + default: + if _, ok := p.constructors[drStr]; !ok { + p.log.Warn("no constructors registered", "requested constructor", drStr, "registered", p.constructors) + continue + } + + // use only key for the driver registration, for example rr-boltdb should be globally available + storage, err := p.constructors[drStr].KVConstruct(k) + if err != nil { + errCh <- errors.E(op, err) + return errCh + } + + // save the storage + p.storages[k] = storage } - - storage, err := p.constructors[drStr].KVConstruct(configKey) - if err != nil { - errCh <- errors.E(op, err) - return errCh - } - - // save the storage - p.storages[k] = storage } continue |