Подготовить HY2XS к production-сборке
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/didip/tollbooth"
|
||||
"github.com/didip/tollbooth/limiter"
|
||||
"github.com/gin-gonic/gin"
|
||||
"hy2xs-admin/model/vo"
|
||||
)
|
||||
|
||||
var limit *limiter.Limiter
|
||||
|
||||
func init() {
|
||||
limit = tollbooth.NewLimiter(5, nil)
|
||||
}
|
||||
|
||||
func RateLimiterHandler() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
httpError := tollbooth.LimitByRequest(limit, c.Writer, c.Request)
|
||||
if httpError != nil {
|
||||
vo.Fail("click too fast", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user