代码拉取完成,页面将自动刷新
同步操作将从 RuleGo/rulego 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright 2023 The RuleGo Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rulego
import (
"errors"
"github.com/rulego/rulego/api/types"
"github.com/rulego/rulego/utils/str"
)
const (
defaultNodeIdPrefix = "node"
)
// RuleNodeCtx 节点组件实例定义
type RuleNodeCtx struct {
//组件实例
types.Node
//组件配置
SelfDefinition *RuleNode
//规则引擎配置
Config types.Config
}
//InitRuleNodeCtx 初始化RuleNodeCtx
func InitRuleNodeCtx(config types.Config, selfDefinition *RuleNode) (*RuleNodeCtx, error) {
node, err := config.ComponentsRegistry.NewNode(selfDefinition.Type)
if err != nil {
return &RuleNodeCtx{}, err
} else {
if selfDefinition.Configuration == nil {
selfDefinition.Configuration = make(types.Configuration)
}
if err = node.Init(config, processGlobalPlaceholders(config, selfDefinition.Configuration)); err != nil {
return &RuleNodeCtx{}, err
} else {
return &RuleNodeCtx{
Node: node,
SelfDefinition: selfDefinition,
Config: config,
}, nil
}
}
}
func (rn *RuleNodeCtx) IsDebugMode() bool {
return rn.SelfDefinition.DebugMode
}
func (rn *RuleNodeCtx) GetNodeId() types.RuleNodeId {
return types.RuleNodeId{Id: rn.SelfDefinition.Id, Type: types.NODE}
}
func (rn *RuleNodeCtx) ReloadSelf(def []byte) error {
if ruleNodeCtx, err := rn.Config.Parser.DecodeRuleNode(rn.Config, def); err == nil {
//先销毁
rn.Destroy()
//重新加载
rn.Copy(ruleNodeCtx.(*RuleNodeCtx))
return nil
} else {
return err
}
}
func (rn *RuleNodeCtx) ReloadChild(_ types.RuleNodeId, _ []byte) error {
return errors.New("not support this func")
}
func (rn *RuleNodeCtx) GetNodeById(_ types.RuleNodeId) (types.NodeCtx, bool) {
return nil, false
}
func (rn *RuleNodeCtx) DSL() []byte {
v, _ := rn.Config.Parser.EncodeRuleNode(rn.SelfDefinition)
return v
}
// Copy 复制
func (rn *RuleNodeCtx) Copy(newCtx *RuleNodeCtx) {
rn.Node = newCtx.Node
rn.SelfDefinition.AdditionalInfo = newCtx.SelfDefinition.AdditionalInfo
rn.SelfDefinition.Name = newCtx.SelfDefinition.Name
rn.SelfDefinition.Type = newCtx.SelfDefinition.Type
rn.SelfDefinition.DebugMode = newCtx.SelfDefinition.DebugMode
rn.SelfDefinition.Configuration = newCtx.SelfDefinition.Configuration
}
// 使用全局配置替换节点占位符配置,例如:${global.propertyKey}
func processGlobalPlaceholders(config types.Config, configuration types.Configuration) types.Configuration {
if config.Properties.Values() != nil {
var result = make(types.Configuration)
for key, value := range configuration {
if strV, ok := value.(string); ok {
result[key] = str.SprintfVar(strV, "global.", config.Properties.Values())
} else {
result[key] = value
}
}
return result
}
return configuration
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。