From 9d43182cd7e0d3ba310661cea50588bf43327d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 25 Nov 2021 11:29:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0is=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/apollo/search.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 +}