|
@@ -20,18 +20,18 @@ return
|
|
|
statusCode:0通过 -1黑名单 1被拦截 2出现验证码
|
|
|
key
|
|
|
*/
|
|
|
-func (a *ReqFilterPoly) IdFilter(ctx g.Ctx, id string) (statusCode int, key string) {
|
|
|
+func (a *ReqFilterPoly) IdFilter(ctx g.Ctx, id string) (statusCode int, key string, inWhite bool) {
|
|
|
//是否开启白名单(开启白名单且在白名单中直接跳过)
|
|
|
if a.Rule.CheckWhite && a.checkWhiteList(id) {
|
|
|
- return 0, id
|
|
|
+ return 0, id, true
|
|
|
}
|
|
|
//检测是否在黑名单中
|
|
|
if a.Rule.CheckBlack && a.checkBackList(id) {
|
|
|
- return -1, id
|
|
|
+ return -1, id, false
|
|
|
}
|
|
|
//检测是否处于验证码校验状态
|
|
|
if a.IsWaitVerify(id) {
|
|
|
- return 2, id
|
|
|
+ return 2, id, false
|
|
|
}
|
|
|
|
|
|
// 阈值校验
|
|
@@ -58,9 +58,9 @@ func (a *ReqFilterPoly) IdFilter(ctx g.Ctx, id string) (statusCode int, key stri
|
|
|
log.WithContext(ctx).Infof("%s 超出最大请求限制,加入临时黑名单", id)
|
|
|
a.addBackList(id, "exceed IdMax")
|
|
|
AllRedis.Del(fmt.Sprintf(RateDataKey, a.Rule.Alias, a.Rule.IdMax[0], id))
|
|
|
- return -1, id
|
|
|
+ return -1, id, false
|
|
|
}
|
|
|
- return statusCode, id
|
|
|
+ return statusCode, id, false
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -70,22 +70,22 @@ ip:请求ip地址
|
|
|
return
|
|
|
statusCode:0通过 -1黑名单 1被拦截 2出现验证码
|
|
|
*/
|
|
|
-func (a *ReqFilterPoly) IpFilter(ctx g.Ctx, ip string) (statusCode int, key string) {
|
|
|
+func (a *ReqFilterPoly) IpFilter(ctx g.Ctx, ip string) (statusCode int, key string, inWhite bool) {
|
|
|
if !a.Rule.BCheckIp {
|
|
|
- return 0, ip
|
|
|
+ return 0, ip, false
|
|
|
}
|
|
|
//是否开启白名单(开启白名单且在白名单中直接跳过)
|
|
|
if a.Rule.CheckWhite && a.checkWhiteList(ip) {
|
|
|
- return 0, ip
|
|
|
+ return 0, ip, true
|
|
|
}
|
|
|
//检测是否在黑名单中
|
|
|
if a.Rule.CheckBlack && a.checkBackList(ip) {
|
|
|
- return -1, ip
|
|
|
+ return -1, ip, false
|
|
|
}
|
|
|
|
|
|
//检测是否处于验证码校验状态
|
|
|
if a.IsWaitVerify(ip) {
|
|
|
- return 2, ip
|
|
|
+ return 2, ip, false
|
|
|
}
|
|
|
|
|
|
for i, v := range a.Rule.IpThreshold {
|
|
@@ -108,7 +108,7 @@ func (a *ReqFilterPoly) IpFilter(ctx g.Ctx, ip string) (statusCode int, key stri
|
|
|
log.WithContext(ctx).Infof("%s 超出最大请求限制,加入临时黑名单", ip)
|
|
|
a.addBackList(ip, "exceed IdMax")
|
|
|
AllRedis.Del(fmt.Sprintf(RateDataKey, a.Rule.Alias, a.Rule.IpMax[0], ip))
|
|
|
- return -1, ip
|
|
|
+ return -1, ip, false
|
|
|
}
|
|
|
- return statusCode, ip
|
|
|
+ return statusCode, ip, false
|
|
|
}
|