-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.go
56 lines (46 loc) · 1.03 KB
/
plugin.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
50
51
52
53
54
55
56
package resetter
import (
"github.com/roadrunner-server/endure/v2/dep"
"github.com/roadrunner-server/errors"
)
const PluginName = "resetter"
// Resetter interface
type Resetter interface {
// Reset reload plugin
Reset() error
// Name of the plugin
Name() string
}
type Plugin struct {
registry map[string]Resetter
}
func (p *Plugin) Init() error {
p.registry = make(map[string]Resetter)
return nil
}
// Reset named service.
func (p *Plugin) Reset(name string) error {
const op = errors.Op("resetter_plugin_reset_by_name")
svc, ok := p.registry[name]
if !ok {
return errors.E(op, errors.Errorf("no such plugin: %s", name))
}
return svc.Reset()
}
// Collects declare services to be collected.
func (p *Plugin) Collects() []*dep.In {
return []*dep.In{
dep.Fits(func(pl any) {
res := pl.(Resetter)
p.registry[res.Name()] = res
}, (*Resetter)(nil)),
}
}
// Name of the service.
func (p *Plugin) Name() string {
return PluginName
}
// RPC returns associated rpc service.
func (p *Plugin) RPC() any {
return &rpc{srv: p}
}