summaryrefslogtreecommitdiff
path: root/plugins/memcached/plugin.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-08-26 18:32:51 +0300
committerValery Piashchynski <[email protected]>2021-08-26 18:32:51 +0300
commitefb3efa98c8555815330274f0618bfc080f4c65c (patch)
treeb3bcabdb22fade6ef06d865d60995bc15f84cf1c /plugins/memcached/plugin.go
parent3212a5b59b6dcd8aa6edac137e945d42f6f9e0ce (diff)
Move drivers to the plugin's root.
Fix #771, add tests. Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/memcached/plugin.go')
-rw-r--r--plugins/memcached/plugin.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/memcached/plugin.go b/plugins/memcached/plugin.go
new file mode 100644
index 00000000..59a2b7cb
--- /dev/null
+++ b/plugins/memcached/plugin.go
@@ -0,0 +1,48 @@
+package memcached
+
+import (
+ "github.com/spiral/errors"
+ "github.com/spiral/roadrunner/v2/common/kv"
+ "github.com/spiral/roadrunner/v2/plugins/config"
+ "github.com/spiral/roadrunner/v2/plugins/logger"
+)
+
+const (
+ PluginName string = "memcached"
+ RootPluginName string = "kv"
+)
+
+type Plugin struct {
+ // config plugin
+ cfgPlugin config.Configurer
+ // logger
+ log logger.Logger
+}
+
+func (s *Plugin) Init(log logger.Logger, cfg config.Configurer) error {
+ if !cfg.Has(RootPluginName) {
+ return errors.E(errors.Disabled)
+ }
+
+ s.cfgPlugin = cfg
+ s.log = log
+ return nil
+}
+
+// Name returns plugin user-friendly name
+func (s *Plugin) Name() string {
+ return PluginName
+}
+
+// Available interface implementation
+func (s *Plugin) Available() {}
+
+func (s *Plugin) KVConstruct(key string) (kv.Storage, error) {
+ const op = errors.Op("boltdb_plugin_provide")
+ st, err := NewMemcachedDriver(s.log, key, s.cfgPlugin)
+ if err != nil {
+ return nil, errors.E(op, err)
+ }
+
+ return st, nil
+}