-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
registry.go
63 lines (50 loc) · 1.38 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package add_kubernetes_metadata
import (
"errors"
"fmt"
p "github.com/elastic/beats/libbeat/plugin"
)
var (
indexerKey = "libbeat.processor.kubernetes.indexer"
matcherKey = "libbeat.processor.kubernetes.matcher"
)
type indexerPlugin struct {
name string
constructor IndexerConstructor
}
func IndexerPlugin(name string, c IndexerConstructor) map[string][]interface{} {
return p.MakePlugin(indexerKey, indexerPlugin{name, c})
}
type matcherPlugin struct {
name string
constructor MatcherConstructor
}
func MatcherPlugin(name string, m MatcherConstructor) map[string][]interface{} {
return p.MakePlugin(matcherKey, matcherPlugin{name, m})
}
func init() {
p.MustRegisterLoader(indexerKey, func(ifc interface{}) error {
i, ok := ifc.(indexerPlugin)
if !ok {
return errors.New("plugin does not match indexer plugin type")
}
name := i.name
if Indexing.indexers[name] != nil {
return fmt.Errorf("indexer type %v already registered", name)
}
Indexing.AddIndexer(name, i.constructor)
return nil
})
p.MustRegisterLoader(matcherKey, func(ifc interface{}) error {
m, ok := ifc.(matcherPlugin)
if !ok {
return errors.New("plugin does not match matcher plugin type")
}
name := m.name
if Indexing.matchers[name] != nil {
return fmt.Errorf("matcher type %v already registered", name)
}
Indexing.AddMatcher(name, m.constructor)
return nil
})
}