From d235aa4edba6f72a4ef099e7674e7870b379c986 Mon Sep 17 00:00:00 2001 From: duyu Date: Thu, 18 Jul 2024 16:48:50 +0800 Subject: [PATCH] verify ip --- app/http/middlewares/ip_verify.go | 14 +++++++++++++- app/http/routes/route.go | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/http/middlewares/ip_verify.go b/app/http/middlewares/ip_verify.go index 9e9ebe3..f522e35 100644 --- a/app/http/middlewares/ip_verify.go +++ b/app/http/middlewares/ip_verify.go @@ -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 + } + } +} diff --git a/app/http/routes/route.go b/app/http/routes/route.go index 0f77993..2a102d5 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -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)