规则引擎

This commit is contained in:
PandaGoAdmin
2023-03-21 11:42:02 +08:00
parent e267703a97
commit 186453f5a6
11 changed files with 102 additions and 42 deletions

View File

@@ -20,6 +20,7 @@ const (
type Factory interface {
Name() string
Category() string
Labels() []string
Create(id string, meta Metadata) (Node, error)
}
@@ -28,7 +29,7 @@ var (
allNodeFactories map[string]Factory = make(map[string]Factory)
// allNodeCategories hold node's metadata by category
allNodeCategories map[string][]string = make(map[string][]string)
allNodeCategories map[string][]map[string]interface{} = make(map[string][]map[string]interface{})
)
// RegisterFactory add a new node factory and classify its category for
@@ -37,9 +38,9 @@ func RegisterFactory(f Factory) {
allNodeFactories[f.Name()] = f
if allNodeCategories[f.Category()] == nil {
allNodeCategories[f.Category()] = []string{}
allNodeCategories[f.Category()] = []map[string]interface{}{}
}
allNodeCategories[f.Category()] = append(allNodeCategories[f.Category()], f.Name())
allNodeCategories[f.Category()] = append(allNodeCategories[f.Category()], map[string]interface{}{"name": f.Name(), "labels": f.Labels()})
}
// NewNode is the only way to create a new node
@@ -51,4 +52,4 @@ func NewNode(nodeType string, id string, meta Metadata) (Node, error) {
}
// GetCategoryNodes return specified category's all nodes
func GetCategoryNodes() map[string][]string { return allNodeCategories }
func GetCategoryNodes() map[string][]map[string]interface{} { return allNodeCategories }