加开关中间件网关登录策略-IP限制

This commit is contained in:
TsMask committed 2023-08-26 17:01:08 +08:00
1 parent 8b300036cd
commit 9a6684b257
1 file changed
+14 -2
+14 -2
View File
@@ -29,17 +29,29 @@ func ArrowIPAddr(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
return
}
// 开关
switchStr := data["switch"].(string)
if switchStr == "0" {
next.ServeHTTP(w, r)
return
}
ipRange := data["ipRange"].(string)
logintimeRange := data["logintime_range"].(string)
// 检查ip
ips := strings.Split(ipRange, "/")
hasIP := false
for _, ip := range ips {
if ipAddr != ip {
if ipAddr == ip {
hasIP = true
}
}
if !hasIP {
services.ResponseErrorWithJson(w, 502, "网关登录策略-IP限制: "+ipAddr)
return
}
}
// 检查开放时间
logintimeRangeArr := strings.Split(logintimeRange, " - ")