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 } } } func VerifyHtmlIp() gin.HandlerFunc { return func(c *gin.Context) { // 读取请求体 reqIp := c.ClientIP() //验证商户是否存在 if reqIp != "172.22.0.1" && reqIp != "117.176.133.38" { common.Error(c, 400, "ip无权限访问") c.Abort() return } } }