throttler

package module
v0.0.0-...-8c17820 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2016 License: MIT Imports: 1 Imported by: 0

README

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!
Goji
// 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.

Interpose
// Limit to 5 requests globally.
middle := interpose.New()
middle.Use(throttler.Limit(5))

See full example.

Alice
// Limit to 5 requests globally.
chain := alice.New(throttler.Limit(5)).Then(handlerFunc)

See full example.

Gorilla/mux
r := mux.NewRouter()
r.HandleFunc("/", handler)

// Limit to 5 requests globally.
limit := throttler.Limit(5)
http.Handle("/", limit(r))

See full example.

DefaultServeMux (net/http)
// Limit to 5 requests globally.
limit := throttler.Limit(5)
http.Handle("/", limit(handlerFunc))

See full example.

Chi
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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Limit

func Limit(limit int) func(http.Handler) http.Handler

Limit create new throttler middleware with a specified limit.

Types

This section is empty.

Directories

Path Synopsis
_examples
chi
mux

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL