chore: 调整解析逻辑
This commit is contained in:
parent
3b038310ab
commit
fa3e0c726e
3 changed files with 28 additions and 51 deletions
|
@ -62,8 +62,6 @@ func payloadToRule(subPayload string) (C.Rule, error) {
|
|||
}
|
||||
|
||||
func parseRule(tp, payload string, params []string) (parsed C.Rule, parseErr error) {
|
||||
parsed, parseErr = ruleparser.ParseSameRule(tp, payload, "", params)
|
||||
if ruleparser.IsUnsupported(parseErr) {
|
||||
switch tp {
|
||||
case "AND":
|
||||
parsed, parseErr = NewAND(payload, "")
|
||||
|
@ -75,8 +73,7 @@ func parseRule(tp, payload string, params []string) (parsed C.Rule, parseErr err
|
|||
noResolve := RC.HasNoResolve(params)
|
||||
parsed, parseErr = RP.NewRuleSet(payload, "", noResolve)
|
||||
default:
|
||||
parseErr = ruleparser.NewUnsupportedError(tp)
|
||||
}
|
||||
parsed, parseErr = ruleparser.ParseSameRule(tp, payload, "", params)
|
||||
}
|
||||
|
||||
if parseErr != nil {
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
)
|
||||
|
||||
func ParseRule(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) {
|
||||
parsed, parseErr = ruleparser.ParseSameRule(tp, payload, target, params)
|
||||
if ruleparser.IsUnsupported(parseErr) {
|
||||
switch tp {
|
||||
case "AND":
|
||||
parsed, parseErr = logic.NewAND(payload, target)
|
||||
|
@ -25,8 +23,7 @@ func ParseRule(tp, payload, target string, params []string) (parsed C.Rule, pars
|
|||
parsed = RC.NewMatch(target)
|
||||
parseErr = nil
|
||||
default:
|
||||
parseErr = ruleparser.NewUnsupportedError(tp)
|
||||
}
|
||||
parsed, parseErr = ruleparser.ParseSameRule(tp, payload, target, params)
|
||||
}
|
||||
|
||||
if parseErr != nil {
|
||||
|
|
|
@ -44,24 +44,7 @@ func ParseSameRule(tp, payload, target string, params []string) (parsed C.Rule,
|
|||
case "IN-TYPE":
|
||||
parsed, parseErr = RC.NewInType(payload, target)
|
||||
default:
|
||||
parseErr = NewUnsupportedError(tp)
|
||||
parseErr = fmt.Errorf("unsupported rule type %s", tp)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type UnsupportedError struct {
|
||||
err string
|
||||
}
|
||||
|
||||
func (ue UnsupportedError) Error() string {
|
||||
return ue.err
|
||||
}
|
||||
|
||||
func NewUnsupportedError(tp any) *UnsupportedError {
|
||||
return &UnsupportedError{err: fmt.Sprintf("unsupported rule type %s", tp)}
|
||||
}
|
||||
|
||||
func IsUnsupported(err error) bool {
|
||||
_, ok := err.(*UnsupportedError)
|
||||
return ok
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue