refactor: 逻辑规则显示效果
This commit is contained in:
parent
1f95c74f1e
commit
11ddac2b5f
3 changed files with 5 additions and 6 deletions
|
@ -29,15 +29,14 @@ func NewAND(payload string, adapter string) (*AND, error) {
|
||||||
and.rules = rules
|
and.rules = rules
|
||||||
payloads := make([]string, 0, len(rules))
|
payloads := make([]string, 0, len(rules))
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
payloads = append(payloads, fmt.Sprintf("(%s)", rule.Payload()))
|
payloads = append(payloads, fmt.Sprintf("(%s,%s)", rule.RuleType().String(), rule.Payload()))
|
||||||
if rule.ShouldResolveIP() {
|
if rule.ShouldResolveIP() {
|
||||||
and.needIP = true
|
and.needIP = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
and.payload = strings.Join(payloads, " && ")
|
and.payload = fmt.Sprintf("(%s)", strings.Join(payloads, " && "))
|
||||||
|
|
||||||
return and, nil
|
return and, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func NewNOT(payload string, adapter string) (*NOT, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
not.rule = rule[0]
|
not.rule = rule[0]
|
||||||
not.payload = fmt.Sprintf("!(%s)", rule[0].Payload())
|
not.payload = fmt.Sprintf("(!(%s,%s))", rule[0].RuleType(), rule[0].Payload())
|
||||||
|
|
||||||
return not, nil
|
return not, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,13 +55,13 @@ func NewOR(payload string, adapter string) (*OR, error) {
|
||||||
or.rules = rules
|
or.rules = rules
|
||||||
payloads := make([]string, 0, len(rules))
|
payloads := make([]string, 0, len(rules))
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
payloads = append(payloads, fmt.Sprintf("(%s)", rule.Payload()))
|
payloads = append(payloads, fmt.Sprintf("(%s,%s)", rule.RuleType(), rule.Payload()))
|
||||||
if rule.ShouldResolveIP() {
|
if rule.ShouldResolveIP() {
|
||||||
or.needIP = true
|
or.needIP = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
or.payload = strings.Join(payloads, " || ")
|
or.payload = fmt.Sprintf("(%s)", strings.Join(payloads, " || "))
|
||||||
return or, nil
|
return or, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue