From 11a7ac9b1091a2c56fbfa5612f17a93866fe30f3 Mon Sep 17 00:00:00 2001 From: Nekohy Date: Sat, 16 Aug 2025 16:37:09 +0800 Subject: [PATCH] feats:custom the key missing condition --- relay/common/override.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/relay/common/override.go b/relay/common/override.go index 00a2ad01..bce80e75 100644 --- a/relay/common/override.go +++ b/relay/common/override.go @@ -9,11 +9,11 @@ import ( ) type ConditionOperation struct { - Path string `json:"path"` // JSON路径 - Mode string `json:"mode"` // full, prefix, suffix, contains, gt, gte, lt, lte - Value interface{} `json:"value"` // 匹配的值 - Invert bool `json:"invert"` // 反选功能,true表示取反结果 - + Path string `json:"path"` // JSON路径 + Mode string `json:"mode"` // full, prefix, suffix, contains, gt, gte, lt, lte + Value interface{} `json:"value"` // 匹配的值 + Invert bool `json:"invert"` // 反选功能,true表示取反结果 + PassMissingKey bool `json:"pass_missing_key"` // 未获取到json key时的行为 } type ParamOperation struct { @@ -99,6 +99,9 @@ func tryParseOperations(paramOverride map[string]interface{}) ([]ParamOperation, if invert, ok := condMap["invert"].(bool); ok { condition.Invert = invert } + if passMissingKey, ok := condMap["pass_missing_key"].(bool); ok { + condition.PassMissingKey = passMissingKey + } operation.Conditions = append(operation.Conditions, condition) } } @@ -150,6 +153,9 @@ func checkConditions(jsonStr string, conditions []ConditionOperation, logic stri func checkSingleCondition(jsonStr string, condition ConditionOperation) (bool, error) { value := gjson.Get(jsonStr, condition.Path) if !value.Exists() { + if condition.PassMissingKey { + return true, nil + } return false, nil }