mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-25 03:48:35 +08:00
规则引擎
This commit is contained in:
62
pkg/rule_engine/nodes/metadata.go
Normal file
62
pkg/rule_engine/nodes/metadata.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user