forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
44 lines (33 loc) · 942 Bytes
/
registry.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
package processors
import (
"errors"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
p "github.com/elastic/beats/libbeat/plugin"
)
type processorPlugin struct {
name string
constr Constructor
}
var pluginKey = "libbeat.processor"
func Plugin(name string, c Constructor) map[string][]interface{} {
return p.MakePlugin(pluginKey, processorPlugin{name, c})
}
func init() {
p.MustRegisterLoader(pluginKey, func(ifc interface{}) error {
p, ok := ifc.(processorPlugin)
if !ok {
return errors.New("plugin does not match processor plugin type")
}
return registry.Register(p.name, p.constr)
})
}
type Constructor func(config *common.Config) (Processor, error)
var registry = NewNamespace()
func RegisterPlugin(name string, constructor Constructor) {
logp.Debug("processors", "Register plugin %s", name)
err := registry.Register(name, constructor)
if err != nil {
panic(err)
}
}