// Apply rate limiting by key and IP
Apply rate limiting by key and IP
// Apply rate limiting by key and IP
func (r *rateLimiter) limit(key string) func(fasthttp.RequestHandler) fasthttp.RequestHandler {
	return func(next fasthttp.RequestHandler) fasthttp.RequestHandler {
		fn := func(ctx *fasthttp.RequestCtx) {
			addr := ctx.RemoteAddr().String()
			l := r.getLimiter(key + addr)
			if !l.limiter.Allow() {
				ctx.Error(http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
				return
			}
			next(ctx)
		}
		return fasthttp.RequestHandler(fn)
	}
}
func ( r * rateLimiter ) limit ( key string ) func ( fasthttp . RequestHandler ) fasthttp . RequestHandler { return func ( next fasthttp . RequestHandler ) fasthttp . RequestHandler { fn := func ( ctx * fasthttp . RequestCtx ) { addr := ctx . RemoteAddr ( ) . String ( ) l := r . getLimiter ( key + addr ) if ! l . limiter . Allow ( ) { ctx . Error ( http . StatusText ( http . StatusTooManyRequests ) , http . StatusTooManyRequests ) return } next ( ctx ) } return fasthttp . RequestHandler ( fn ) } }
Apply rate limiting by key and IP
Apply rate limiting by key and IP