增加is判断

This commit is contained in:
白茶清欢 2021-11-25 11:29:53 +08:00
parent 04592e840f
commit 9d43182cd7

View File

@ -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
}