com.snow.auto_monitor/app/http/middlewares/ip_verify.go

27 lines
513 B
Go
Raw Normal View History

2024-07-12 18:11:21 +08:00
package middlewares
import (
common "com.snow.auto_monitor/app/http/controllers"
wlmod "com.snow.auto_monitor/app/models/whitelist"
"github.com/gin-gonic/gin"
)
func VerifyIp() gin.HandlerFunc {
return func(c *gin.Context) {
// 读取请求体
reqIp := c.ClientIP()
//验证商户是否存在
_, has, err := wlmod.GetInstance().GetByIp(reqIp)
if err != nil {
common.Error500(c)
c.Abort()
return
}
if !has {
common.Error(c, 400, "ip无权限访问")
c.Abort()
return
}
}
}