Open imokoi opened 1 month ago
you can wrap your handlers in middleware, where you set rate limiter from lib golang.org/x/time/rate
example:
func rateLimiter(next func(ctx context.Context, bot *Bot, update *models.Update)) HandlerFunc {
limiter := rate.NewLimiter(2, 4)
return HandlerFunc(func(ctx context.Context, bot *Bot, update *models.Update) {
if !limiter.Allow() {
// process if now allow
} else {
next(w, r)
}
})
}
I have plans to add rate limit support to the library
Hello, is there any example for rate limiting? avoid error code 429.