-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugins.go
60 lines (51 loc) · 1.47 KB
/
plugins.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
package transport
import (
"fmt"
)
// PluginsMap Store available plugins, include input, adapt, output.
type PluginsMap struct {
Inputers map[string]Inputer
Outputers map[string]Outputer
Adapters map[string]Adapter
}
// NewPluginsMap map instance
func NewPluginsMap() *PluginsMap {
Plugins = new(PluginsMap)
Plugins.Inputers = make(map[string]Inputer)
Plugins.Outputers = make(map[string]Outputer)
Plugins.Adapters = make(map[string]Adapter)
return Plugins
}
// Plugins Global plugins instance
var Plugins *PluginsMap
// RegistInputer Regist input plugin
func RegistInputer(key string, input Inputer) {
Plugins.Inputers[key] = input
}
// RegistOutputer Regist out plugin
func RegistOutputer(key string, output Outputer) {
Plugins.Outputers[key] = output
}
// RegistHandler Regist adapt plugin
func RegistHandler(key string, a Adapter) {
Plugins.Adapters[key] = a
}
// PluginDetail Show plugins information
func PluginDetail() string {
str := fmt.Sprintf("%-16s %s\n", "[Inputs]", "version")
for name, inputer := range Plugins.Inputers {
str += fmt.Sprintf(" %-15s %s\n", name, inputer.Version())
}
str += fmt.Sprintf("%-17s\n", "[Adapters]")
for name, adapter := range Plugins.Adapters {
str += fmt.Sprintf(" %-15s %s\n", name, adapter.Version())
}
str += fmt.Sprintf("%-17s\n", "[Outputers]")
for name, outputer := range Plugins.Outputers {
str += fmt.Sprintf(" %-15s %s\n", name, outputer.Version())
}
return str
}
func init() {
Plugins = NewPluginsMap()
}