-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
57 lines (45 loc) · 1.52 KB
/
main.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
//go:build plugins
// +build plugins
package plugins
import (
"fmt"
agent_entities "github.com/bolt-observer/agent/entities"
"github.com/bolt-observer/agent/filter"
api "github.com/bolt-observer/agent/lightning"
"github.com/golang/glog"
"github.com/urfave/cli"
)
// Here we have no dependency on the actual plugin
var (
// Plugins is global map which holds registered plugins
Plugins map[string]agent_entities.Plugin
// Both of those are filled during init
// AllPluginFlags hold the extra flags for plugins
AllPluginFlags []cli.Flag
// AllPluginCommands hold the extra commands for plugins
AllPluginCommands []cli.Command
// RegisteredPlugins
RegisteredPlugins []PluginData
)
// InitPluginFn signature of init plugin function
type InitPluginFn func(lnAPI api.NewAPICall, filter filter.FilteringInterface, cmdCtx *cli.Context, nodeDataInvalidator agent_entities.Invalidatable) (agent_entities.Plugin, error)
// PluginData structure
type PluginData struct {
Name string
Init InitPluginFn
}
func InitPlugins(lnAPI api.NewAPICall, filter filter.FilteringInterface, cmdCtx *cli.Context, nodeDataInvalidator agent_entities.Invalidatable) error {
Plugins = make(map[string]agent_entities.Plugin)
for _, p := range RegisteredPlugins {
plugin, err := p.Init(lnAPI, filter, cmdCtx, nodeDataInvalidator)
if err != nil {
glog.Warningf("Plugin %s had an error %v\n", p.Name, err)
return err
}
if plugin == nil {
return fmt.Errorf("%s plugin failed to initialize", p.Name)
}
Plugins[p.Name] = plugin
}
return nil
}