More aggressive rate limit

This commit is contained in:
Manu Mtz-Almeida 2015-05-14 20:43:33 +02:00
parent 3f48e0d45c
commit ef93e8beff
2 changed files with 7 additions and 4 deletions

View File

@ -27,7 +27,7 @@ func StartGin() {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
router := gin.New() router := gin.New()
router.Use(rateLimit, gin.Recovery(), gin.Logger()) router.Use(rateLimit, gin.Recovery())
router.LoadHTMLGlob("resources/*.templ.html") router.LoadHTMLGlob("resources/*.templ.html")
router.Static("/static", "resources/static") router.Static("/static", "resources/static")
router.GET("/", index) router.GET("/", index)

View File

@ -13,9 +13,12 @@ import (
func rateLimit(c *gin.Context) { func rateLimit(c *gin.Context) {
ip := c.ClientIP() ip := c.ClientIP()
value := ips.Add(ip, 1) value := ips.Add(ip, 1)
if value > 800 { if int(value)%200 == 0 {
if int(value)%700 == 0 { log.Printf("ip: %s, count: %f\n", ip, value)
log.Printf("ip block: %s, count: %f\n", ip, value) }
if value > 300 {
if int(value)%200 == 0 {
log.Printf("ip blocked", ip, value)
} }
c.AbortWithStatus(503) c.AbortWithStatus(503)
} }