RuleChain Validator Aspect
# Rule Chain Initialization Validator
The Rule Chain Initialization Validator is an important component used to verify whether the structure and configuration of a rule chain comply with relevant rules before the rule chain is started. Below is a detailed introduction to the Rule Chain Initialization Validator.
# Function Overview
# Sub-Rule Chains Are Not Allowed to Create Endpoint
Components
- Validation Rule: If a sub-rule chain (i.e., a rule chain with the
Root
attribute set tofalse
) contains anEndpoint
component, an error will be triggered. - Error Message:
ErrNotAllowEndpointNode
indicates that sub-rule chains are not allowed to createEndpoint
components.
# Cycle Detection
- Validation Rule: Nodes in the rule chain are not allowed to form cycles. If a cycle is detected, an error will be triggered. (The
config.allowCycle
switch controls whether cycles are allowed. The default isfalse
, indicating that cycles are not allowed.) - Error Message:
ErrCycleDetected
indicates that a cycle reference has been detected in the rule chain.
# Custom Validation Rules
# Creating Validation Functions
Users can create custom validation functions by defining functions with the following signature:
func(config types.Config, def *types.RuleChain) error
1
Where:
config
is the configuration information of the rule chain.def
is the definition of the rule chain.
# Registering Validation Rules
Use the Rules.AddRule()
method to register custom validation functions with the rule validator. For example:
Rules.AddRule(func(config types.Config, def *types.RuleChain) error {
if def != nil && len(def.Metadata.Nodes) > 10 {
return errors.New("the rule chain cannot contain more than 10 nodes")
}
return nil
})
1
2
3
4
5
6
2
3
4
5
6
Edit this page on GitHub (opens new window)
Last Updated: 2025/03/01, 07:42:36