func SetUp (maxBurstSize int) gin.HandlerFunc {
// rate.Every(time.Second*1) 每秒添加一个访问名额
// maxBurstSize 最大访问名额
limiter := rate.NewLimiter(rate.Every(time.Second*1), maxBurstSize)
return func(c *gin.Context) {
if limiter.Allow() {
c.Next()
return
}
c.String(400, "Too many requests")
c.Abort()
return
}
}