From e33ea855d75de1a781e825fd0c46350c4310546c Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Thu, 14 May 2015 22:49:42 +0200 Subject: [PATCH] Message for attackers --- examples/realtime-advanced/routes.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/realtime-advanced/routes.go b/examples/realtime-advanced/routes.go index f982173..bc516fc 100644 --- a/examples/realtime-advanced/routes.go +++ b/examples/realtime-advanced/routes.go @@ -11,16 +11,18 @@ import ( ) func rateLimit(c *gin.Context) { + ip := c.ClientIP() - value := ips.Add(ip, 1) - if int(value)%50 == 0 { - fmt.Printf("ip: %s, count: %d\n", ip, int(value)) + value := int(ips.Add(ip, 1)) + if value%10 == 0 { + fmt.Printf("ip: %s, count: %d\n", ip, value) } - if value >= 200 { - if int(value)%200 == 0 { + if value >= 100 { + if value%100 == 0 { fmt.Println("ip blocked") } - c.AbortWithStatus(503) + c.Abort() + c.String(503, "you were automatically banned :)") } }