Any example for rate limiting
Hello, is there any example for rate limiting? avoid error code 429.
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
I have plans to add rate limit support to the library
any updates?
This is not an easy task for a universal solution.
What behavior do you expect if the call call has returned 429? Automatic attempt to re -send? But if we do not return the error, your application will not find out about the error and will constantly try to repeat the request. And he will not know about what has reached the limits.
idk, hoped for something like https://github.com/grammyjs/grammY has.