Golang HTTP middleware to throttle the number of requests processed at a time.
- Goji
- Interpose
- Alice
- Gorilla/mux
- DefaultServeMux (net/http)
- Chi
- ...don't see your favorite router/framework? We accept Pull Requests!
// Limit to 5 requests globally.
goji.Use(throttler.Limit(5))
// Limit /admin route to 2 requests.
admin := web.New()
admin.Use(throttler.Limit(2))
admin.Get("/*", handler)
See full example.
// Limit to 5 requests globally.
middle := interpose.New()
middle.Use(throttler.Limit(5))
See full example.
// Limit to 5 requests globally.
chain := alice.New(throttler.Limit(5)).Then(handlerFunc)
See full example.
r := mux.NewRouter()
r.HandleFunc("/", handler)
// Limit to 5 requests globally.
limit := throttler.Limit(5)
http.Handle("/", limit(r))
See full example.
// Limit to 5 requests globally.
limit := throttler.Limit(5)
http.Handle("/", limit(handlerFunc))
See full example.
r := chi.NewRouter()
// Limit to 5 requests globally.
r.Use(throttler.Limit(5))
r.Get("/*", handler)
// Limit to 2 requests for admin sub-router
admin := chi.NewRouter()
admin.Use(throttler.Limit(2))
See full example.
Throttler is licensed under the MIT License.