规则引擎

This commit is contained in:
PandaGoAdmin
2023-02-28 14:56:21 +08:00
parent e048fa53a5
commit 8e854ce527
13 changed files with 667 additions and 215 deletions

View File

@@ -0,0 +1,62 @@
package nodes
import (
"fmt"
"github.com/XM-GO/PandaKit/utils"
)
const (
NODE_CONFIG_MESSAGE_TYPE_KEY = "messageTypeKey"
NODE_CONFIG_ORIGINATOR_TYPE_KEY = "originatorTypeKey"
)
type Metadata interface {
Keys() []string
With(key string, val interface{}) Metadata
Value(key string) (interface{}, error)
DecodePath(rawVal interface{}) error
}
type nodeMetadata struct {
keypairs map[string]interface{}
}
func NewMetadata() Metadata {
return &nodeMetadata{
keypairs: make(map[string]interface{}),
}
}
func NewMetadataWithString(vals string) Metadata {
return &nodeMetadata{}
}
func NewMetadataWithValues(vals map[string]interface{}) Metadata {
return &nodeMetadata{
keypairs: vals,
}
}
func (c *nodeMetadata) Keys() []string {
keys := []string{}
for key, _ := range c.keypairs {
keys = append(keys, key)
}
return keys
}
func (c *nodeMetadata) Value(key string) (interface{}, error) {
if val, found := c.keypairs[key]; found {
return val, nil
}
return nil, fmt.Errorf("key '%s' not found", key)
}
func (c *nodeMetadata) With(key string, val interface{}) Metadata {
c.keypairs[key] = val
return c
}
func (c *nodeMetadata) DecodePath(rawVal interface{}) error {
return utils.Map2Struct(c.keypairs, rawVal)
}