summaryrefslogtreecommitdiff
path: root/plugins/memcached/plugin.go
blob: 59a2b7cb00ef57412ee595b00a44add50af41920 (plain)
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
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
}