mirror of
https://github.com/gin-gonic/gin.git
synced 2025-06-18 00:54:12 +08:00
Adds rate limiting
This commit is contained in:
@ -3,12 +3,24 @@ package main
|
||||
import (
|
||||
"html"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
c.AbortWithStatus(503)
|
||||
}
|
||||
}
|
||||
|
||||
func index(c *gin.Context) {
|
||||
c.Redirect(301, "/room/hn")
|
||||
}
|
||||
|
Reference in New Issue
Block a user