-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.go
62 lines (51 loc) · 1.18 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
57
58
59
60
61
62
package config
import (
"github.com/roadrunner-server/endure/v2/dep"
"github.com/roadrunner-server/errors"
"github.com/rumorsflow/rumors/v2/pkg/config"
"time"
)
const PluginName string = "config"
type Plugin struct {
Path string
Prefix string
Type string
ReadInCfg []byte
// user defined Flags in the form of <option>.<key> = <value>
// which overwrites initial config key
Flags []string
// Timeout ...
Timeout time.Duration
Version string
cfg config.Configurer
}
// Init config provider.
func (p *Plugin) Init() error {
const op = errors.Op("config_plugin_init")
if cfg, err := config.NewConfigurer(
p.Version,
p.Timeout,
config.WithPath(p.Path),
config.WithPrefix(p.Prefix),
config.WithConfigType(p.Type),
config.WithReadInCfg(p.ReadInCfg),
config.WithFlags(p.Flags),
); err != nil {
return errors.E(op, err)
} else {
p.cfg = cfg
}
return nil
}
func (p *Plugin) Provides() []*dep.Out {
return []*dep.Out{
dep.Bind((*config.Configurer)(nil), p.ServiceConfigurer),
}
}
func (p *Plugin) ServiceConfigurer() config.Configurer {
return p.cfg
}
// Name returns user-friendly plugin name
func (p *Plugin) Name() string {
return PluginName
}