forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codecs.go
38 lines (30 loc) · 747 Bytes
/
codecs.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
package codecs
import (
"errors"
"fmt"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/plugin"
)
type codecPlugin struct {
name string
factory outputs.CodecFactory
}
var pluginKey = "libbeat.output.codec"
func Plugin(name string, f outputs.CodecFactory) map[string][]interface{} {
return plugin.MakePlugin(name, codecPlugin{name, f})
}
func init() {
plugin.MustRegisterLoader(pluginKey, func(ifc interface{}) (err error) {
b, ok := ifc.(codecPlugin)
if !ok {
return errors.New("plugin does not match output codec plugin type")
}
defer func() {
if msg := recover(); msg != nil {
err = fmt.Errorf("%s", msg)
}
}()
outputs.RegisterOutputCodec(b.name, b.factory)
return
})
}