-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbasic_plugin.go
More file actions
64 lines (53 loc) · 1.48 KB
/
basic_plugin.go
File metadata and controls
64 lines (53 loc) · 1.48 KB
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
63
64
package helper
import (
"github.com/bluemedora/bplogagent/errors"
"go.uber.org/zap"
)
// BasicPluginConfig provides a basic implemention for a plugin config.
type BasicPluginConfig struct {
PluginID string `mapstructure:"id" yaml:"id"`
PluginType string `mapstructure:"type" yaml:"type"`
}
// ID will return the plugin id.
func (c BasicPluginConfig) ID() string {
return c.PluginID
}
// Type will return the plugin type.
func (c BasicPluginConfig) Type() string {
return c.PluginType
}
// Build will build a basic plugin.
func (c BasicPluginConfig) Build(logger *zap.SugaredLogger) (BasicPlugin, error) {
if c.PluginID == "" {
return BasicPlugin{}, errors.NewError(
"Plugin config is missing the `id` field.",
"Ensure that all plugins have a uniquely defined `id` field.",
)
}
if c.PluginType == "" {
return BasicPlugin{}, errors.NewError(
"Plugin config is missing the `type` field.",
"Ensure that all plugins have a defined `type` field.",
)
}
plugin := BasicPlugin{
PluginID: c.PluginID,
PluginType: c.PluginType,
SugaredLogger: logger.With("plugin_id", c.PluginID, "plugin_type", c.PluginType),
}
return plugin, nil
}
// BasicPlugin provides a basic implementation of a plugin.
type BasicPlugin struct {
PluginID string
PluginType string
*zap.SugaredLogger
}
// ID will return the plugin id.
func (b *BasicPlugin) ID() string {
return b.PluginID
}
// Type will return the plugin type.
func (b *BasicPlugin) Type() string {
return b.PluginType
}