mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-13 05:23:44 +08:00
版本预发布
This commit is contained in:
36
server/internal/logic/middleware/limit_develop.go
Normal file
36
server/internal/logic/middleware/limit_develop.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"hotgo/internal/library/location"
|
||||
"hotgo/internal/library/response"
|
||||
)
|
||||
|
||||
// Develop 开发工具白名单过滤
|
||||
func (s *sMiddleware) Develop(r *ghttp.Request) {
|
||||
ips := g.Cfg().MustGet(r.Context(), "hggen.allowedIPs").Strings()
|
||||
if len(ips) == 0 {
|
||||
response.JsonExit(r, gcode.CodeNotSupported.Code(), "请配置生成白名单!")
|
||||
}
|
||||
|
||||
if !gstr.InArray(ips, "*") {
|
||||
cuIp := location.GetClientIp(r)
|
||||
ok := false
|
||||
for _, ip := range ips {
|
||||
if ip == cuIp {
|
||||
ok = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !ok {
|
||||
response.JsonExit(r, gcode.CodeNotSupported.Code(), fmt.Sprintf("当前IP[%s]没有配置生成白名单!", cuIp))
|
||||
}
|
||||
}
|
||||
|
||||
r.Middleware.Next()
|
||||
}
|
Reference in New Issue
Block a user