verify ip

This commit is contained in:
duyu 2024-07-18 16:48:50 +08:00
parent 016036905b
commit d235aa4edb
2 changed files with 16 additions and 1 deletions

View File

@ -8,7 +8,6 @@ import (
func VerifyIp() gin.HandlerFunc {
return func(c *gin.Context) {
return
// 读取请求体
reqIp := c.ClientIP()
//验证商户是否存在
@ -25,3 +24,16 @@ func VerifyIp() gin.HandlerFunc {
}
}
}
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
}
}
}

View File

@ -69,6 +69,7 @@ func RegisterRoute(router *gin.Engine) {
}
orders := router.Group("/orders")
orders.Use(middlewares.VerifyHtmlIp())
{
orders.POST("/get_by_id", ordersCon.GetById)
orders.POST("/search", ordersCon.Search)
@ -78,6 +79,7 @@ func RegisterRoute(router *gin.Engine) {
}
product := router.Group("/product")
product.Use(middlewares.VerifyHtmlIp())
{
product.POST("/get_by_id", proCon.GetById)
product.POST("/search", proCon.Search)
@ -87,6 +89,7 @@ func RegisterRoute(router *gin.Engine) {
}
whitelist := router.Group("/whitelist")
whitelist.Use(middlewares.VerifyHtmlIp())
{
whitelist.POST("/get_by_id", wlCon.GetById)
whitelist.POST("/search", wlCon.Search)