Skip to content

Commit

Permalink
More aggressive rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed May 14, 2015
1 parent 74967c0 commit 237c042
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion realtime-advanced/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions realtime-advanced/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 237c042

Please sign in to comment.