-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
plugin_manager.go
33 lines (26 loc) · 890 Bytes
/
plugin_manager.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
package plugin
import (
"github.com/daveshanley/vacuum/model"
"gopkg.in/yaml.v3"
)
type FunctionSchema func() model.RuleFunctionSchema
type FunctionHook func(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult
type Manager struct {
customFunctions map[string]model.RuleFunction
}
func CreatePluginManager() *Manager {
return &Manager{
customFunctions: make(map[string]model.RuleFunction),
}
}
// RegisterFunction allows a custom function to be hooked in
func (pm *Manager) RegisterFunction(name string, ruleFunction model.RuleFunction) {
pm.customFunctions[name] = ruleFunction
}
// LoadedFunctionCount returns the number of available and ready to use functions.
func (pm *Manager) LoadedFunctionCount() int {
return len(pm.customFunctions)
}
func (pm *Manager) GetCustomFunctions() map[string]model.RuleFunction {
return pm.customFunctions
}