27 lines
513 B
Go
27 lines
513 B
Go
|
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
|
||
|
}
|
||
|
}
|
||
|
}
|