diff --git a/middleware/apollo/search.go b/middleware/apollo/search.go index f067ce3..681df10 100644 --- a/middleware/apollo/search.go +++ b/middleware/apollo/search.go @@ -10,6 +10,7 @@ package apollo import ( "encoding/json" "errors" + "fmt" "git.zhangdeman.cn/zhangdeman/gopkg/util" ) @@ -95,5 +96,29 @@ func Search(key string, inputData map[string]interface{}, receiver interface{}) // // Date : 10:59 下午 2021/11/24 func checkRule(rule Rule, inputData map[string]interface{}) bool { + for _, cond := range rule.ConditionList { + val, exist := inputData[cond.InputKey] + if !exist { + // 输入的key 不存在, 不符合规则 + return false + } + switch cond.Operate { + case OperateTypeIs: + if !is(val, cond.TargetValue) { + return false + } + default: + return false + } + } return true } + +// is 判断是否相等 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:28 上午 2021/11/25 +func is(inputVal interface{}, targetValue string) bool { + return fmt.Sprintf("%v", inputVal) == targetValue +}