From 11ddac2b5f1a0b34eafe418155b779be92790081 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Mon, 30 May 2022 13:58:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=80=BB=E8=BE=91=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rule/logic/and.go | 5 ++--- rule/logic/not.go | 2 +- rule/logic/or.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rule/logic/and.go b/rule/logic/and.go index f2d543790..876bd71bf 100644 --- a/rule/logic/and.go +++ b/rule/logic/and.go @@ -29,15 +29,14 @@ func NewAND(payload string, adapter string) (*AND, error) { and.rules = rules payloads := make([]string, 0, len(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() { and.needIP = true break } } - and.payload = strings.Join(payloads, " && ") - + and.payload = fmt.Sprintf("(%s)", strings.Join(payloads, " && ")) return and, nil } diff --git a/rule/logic/not.go b/rule/logic/not.go index 20fb90c5a..4259acbd9 100644 --- a/rule/logic/not.go +++ b/rule/logic/not.go @@ -29,7 +29,7 @@ func NewNOT(payload string, adapter string) (*NOT, error) { } 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 } diff --git a/rule/logic/or.go b/rule/logic/or.go index b79188c3a..80b8eef33 100644 --- a/rule/logic/or.go +++ b/rule/logic/or.go @@ -55,13 +55,13 @@ func NewOR(payload string, adapter string) (*OR, error) { or.rules = rules payloads := make([]string, 0, len(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() { or.needIP = true break } } - or.payload = strings.Join(payloads, " || ") + or.payload = fmt.Sprintf("(%s)", strings.Join(payloads, " || ")) return or, nil }