Skip to content

DisruptiveMind/throttler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Throttler

Golang HTTP middleware to throttle the number of requests processed at a time.

GoDoc Travis

Usage

  1. Goji
  2. Interpose
  3. Alice
  4. Gorilla/mux
  5. DefaultServeMux (net/http)
  6. Chi
  7. ...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.

License

Throttler is licensed under the MIT License.

About

Golang HTTP middleware to throttle the number of requests processed at a time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages