mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-09-18 01:06:40 +08:00
24 lines
640 B
Go
24 lines
640 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gogf/gf/v2/errors/gcode"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"hotgo/internal/global"
|
|
"hotgo/internal/library/location"
|
|
"hotgo/internal/library/response"
|
|
)
|
|
|
|
// Blacklist IP黑名单限制中间件
|
|
func (s *sMiddleware) Blacklist(r *ghttp.Request) {
|
|
if global.Blacklists != nil {
|
|
if _, ok := global.Blacklists[location.GetClientIp(r)]; ok {
|
|
response.JsonExit(r, gcode.CodeServerBusy.Code(), "请求异常,已被封禁,如有疑问请联系管理员!")
|
|
}
|
|
} else {
|
|
g.Log().Warningf(r.Context(), "blacklists uninitialized")
|
|
}
|
|
|
|
r.Middleware.Next()
|
|
}
|