From ef93e8beff3fb6b7000ce977763f233ebc1ce54d Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Thu, 14 May 2015 20:43:33 +0200 Subject: [PATCH] More aggressive rate limit --- examples/realtime-advanced/main.go | 2 +- examples/realtime-advanced/routes.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/realtime-advanced/main.go b/examples/realtime-advanced/main.go index 6aa781ed..1f3c8585 100644 --- a/examples/realtime-advanced/main.go +++ b/examples/realtime-advanced/main.go @@ -27,7 +27,7 @@ func StartGin() { gin.SetMode(gin.ReleaseMode) router := gin.New() - router.Use(rateLimit, gin.Recovery(), gin.Logger()) + router.Use(rateLimit, gin.Recovery()) router.LoadHTMLGlob("resources/*.templ.html") router.Static("/static", "resources/static") router.GET("/", index) diff --git a/examples/realtime-advanced/routes.go b/examples/realtime-advanced/routes.go index 8a7ac646..71c2ceb0 100644 --- a/examples/realtime-advanced/routes.go +++ b/examples/realtime-advanced/routes.go @@ -13,9 +13,12 @@ import ( func rateLimit(c *gin.Context) { ip := c.ClientIP() value := ips.Add(ip, 1) - if value > 800 { - if int(value)%700 == 0 { - log.Printf("ip block: %s, count: %f\n", ip, value) + if int(value)%200 == 0 { + log.Printf("ip: %s, count: %f\n", ip, value) + } + if value > 300 { + if int(value)%200 == 0 { + log.Printf("ip blocked", ip, value) } c.AbortWithStatus(503) }