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
Rootattribute set tofalse) contains anEndpointcomponent, an error will be triggered. - Error Message:
ErrNotAllowEndpointNodeindicates that sub-rule chains are not allowed to createEndpointcomponents.
# 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.allowCycleswitch controls whether cycles are allowed. The default isfalse, indicating that cycles are not allowed.) - Error Message:
ErrCycleDetectedindicates 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:
configis the configuration information of the rule chain.defis 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/09/03, 10:09:04