@@ -134,12 +134,15 @@ func WithRequestMatchPagesEnterprise(
134134 return WithRequestMatchPages (ep , pages ... )
135135}
136136
137- // WithRateLimit enforces a rate limit using [golang.org/x/time/rate].
137+ // rateLimitMiddleware enforces a rate limit using [golang.org/x/time/rate].
138138// rps is the number of requests per second allowed by the rate limiter.
139- func WithRateLimit (rps float64 ) MockBackendOption {
140- limiter := rate .NewLimiter (rate .Limit (rps ), 1 )
139+ // Higher burst values allow more calls to happen at once.
140+ // A zero value for burst will not allow any events, unless rps == [rate.Inf].
141+ // This middleware is intended to be used with [github.com/gorilla/mux].
142+ func rateLimitMiddleware (rps float64 , burst int ) func (next http.Handler ) http.Handler {
143+ limiter := rate .NewLimiter (rate .Limit (rps ), burst )
141144
142- rateLimitMiddleware := func (next http.Handler ) http.Handler {
145+ return func (next http.Handler ) http.Handler {
143146 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
144147 if ! limiter .Allow () {
145148 // These values are based on this bit of logic within [github.com/google/go-github]:
@@ -153,8 +156,11 @@ func WithRateLimit(rps float64) MockBackendOption {
153156 next .ServeHTTP (w , r )
154157 })
155158 }
159+ }
156160
161+ // WithRateLimit enforces a rate limit on the mocked [http.Client].
162+ func WithRateLimit (rps float64 , burst int ) MockBackendOption {
157163 return func (router * mux.Router ) {
158- router .Use (rateLimitMiddleware )
164+ router .Use (rateLimitMiddleware ( rps , burst ) )
159165 }
160166}
0 commit comments