Documentation
¶
Index ¶
- Constants
- Variables
- func CheckLogicExpressionAndFormat(logic string) (string, error)
- func GetRuleIDsByLogicExpression(logic string) ([]int, error)
- type Node
- type Rule
- type Rules
- func NewRulesWithArrayAndLogic(rules []*Rule, logic string) (*Rules, error)
- func NewRulesWithArrayAndLogicAndInfo(rules []*Rule, logic string, extractInfo map[string]string) (*Rules, error)
- func NewRulesWithJSONAndLogic(jsonStr []byte, logic string) (*Rules, error)
- func NewRulesWithJSONAndLogicAndInfo(jsonStr []byte, logic string, extractInfo map[string]string) (*Rules, error)
- func (rs *Rules) Fit(o interface{}) (bool, map[int]string)
- func (rs *Rules) FitAskVal(o interface{}) (bool, map[int]string, map[int]interface{})
- func (rs *Rules) FitWithMap(o map[string]interface{}) (bool, map[int]string)
- func (rs *Rules) FitWithMapAskVal(o map[string]interface{}) (bool, map[int]string, map[int]interface{})
- type RulesList
- func (rst *RulesList) Fit(o interface{}) *Rules
- func (rst *RulesList) FitGetFloat64(o interface{}) (bool, float64)
- func (rst *RulesList) FitGetInt64(o interface{}) (bool, int64)
- func (rst *RulesList) FitGetStr(o interface{}) (bool, string)
- func (rst *RulesList) FitWithMap(o map[string]interface{}) *Rules
Constants ¶
const ( // OperatorAnd and OperatorAnd operator = "and" // OperatorOr or OperatorOr operator = "or" // OperatorNot not OperatorNot operator = "not" )
const EmptyFloat64 = 0
EmptyFloat64 空数字
const EmptyStr = ""
EmptyStr 空串
const PatternNumber = "^\\d*$"
PatternNumber 纯数字的正则表达式
const Space = " "
Space 空格
Variables ¶
var ValidAtomOperatorsDisplay = []string{"=", ">", "<", ">=", "<=", "!=", "in", "nin", "regex", "empty", "nempty", "between", "intersect"}
ValidAtomOperatorsDisplay 有效子规则运算符-展示
var ValidOperators = []string{"and", "or", "not"}
ValidOperators 有效逻辑运算符
Functions ¶
func CheckLogicExpressionAndFormat ¶
CheckLogicExpressionAndFormat 检查逻辑表达式正确性,并返回formatted
func GetRuleIDsByLogicExpression ¶
GetRuleIDsByLogicExpression 根据逻辑表达式得到规则id列表
Types ¶
type Node ¶
type Node struct {
Expr string // 分割的logic表达式
ChildrenOp string // 孩子树之间的运算符: and, or, not
Val bool // 节点值
Computed bool // 节点值被计算过
Leaf bool // 是否叶子节点
Should bool // 为了Fit为true,此节点必须的值
Blamed bool // 此节点为了Fit为true,有责任必须为某值
Children []*Node // 孩子树
}
Node 树节点
type Rule ¶
type Rule struct {
Op string `json:"op"` // 算符
Key string `json:"key"` // 目标变量键名
Val interface{} `json:"val"` // 目标变量子规则存值
ID int `json:"id"` // 子规则ID
Msg string `json:"msg"` // 该规则抛出的负提示
}
Rule 最小单元,子规则
type Rules ¶
type Rules struct {
Rules []*Rule // 子规则集合
Logic string // 逻辑表达式,使用子规则ID运算表达
Name string // 规则名称
Msg string // 规则抛出的负提示
Val interface{} // 改规则所代表的存值
}
Rules 规则,拥有逻辑表达式
func NewRulesWithArrayAndLogic ¶
NewRulesWithArrayAndLogic 用rule数组构造Rules的标准方法,logic表达式如果没有则传空字符串
func NewRulesWithArrayAndLogicAndInfo ¶
func NewRulesWithArrayAndLogicAndInfo(rules []*Rule, logic string, extractInfo map[string]string) (*Rules, error)
NewRulesWithArrayAndLogicAndInfo 用rule数组构造Rules的完全方法,logic表达式如果没有则传空字符串, ["name": "规则名称", "msg": "规则不符合的提示"]
func NewRulesWithJSONAndLogic ¶
NewRulesWithJSONAndLogic 用json串构造Rules的标准方法,logic表达式如果没有则传空字符串
func NewRulesWithJSONAndLogicAndInfo ¶
func NewRulesWithJSONAndLogicAndInfo(jsonStr []byte, logic string, extractInfo map[string]string) (*Rules, error)
NewRulesWithJSONAndLogicAndInfo 用json串构造Rules的完全方法,logic表达式如果没有则传空字符串, ["name": "规则名称", "msg": "规则不符合的提示"]
func (*Rules) FitWithMap ¶
FitWithMap Rules匹配map
type RulesList ¶
RulesList 规则组,顺序即优先级
func NewRulesList ¶
NewRulesList RulesList的构造方法,["name": "规则集的名称", "msg": "规则集的简述"]
func (*RulesList) FitGetFloat64 ¶
FitGetFloat64 return hit value, float64
func (*RulesList) FitGetInt64 ¶
FitGetInt64 return hit value, int64
func (*RulesList) FitWithMap ¶
FitWithMap RulesList's fit, means hitting first rules in array