Documentation ¶
Overview ¶
Package proxy provides a rate-limit proxy middleware using the golang.org/x/time/rate lib.
Sample backend extra config
... "extra_config": { ... "github.com/badboyd/krakend-ratelimit/rate/proxy": { "maxRate": 100, "capacity": 100 }, ... }, ...
Adding the middleware to your proxy stack
import rate "github.com/badboyd/krakend-ratelimit/rate/proxy" ... var p proxy.Proxy var backend *config.Backend ... p = rate.NewMiddleware(backend)(p) ...
The ratelimit package provides an efficient token bucket implementation. See https://golang.org/x/time/rate and http://en.wikipedia.org/wiki/Token_bucket for more details.
Index ¶
Constants ¶
const Namespace = "github.com/badboyd/krakend-ratelimit/rate/proxy"
Namespace is the key to use to store and access the custom config data for the proxy
Variables ¶
var ZeroCfg = Config{}
ZeroCfg is the zero value for the Config struct
Functions ¶
func BackendFactory ¶
func BackendFactory(next proxy.BackendFactory) proxy.BackendFactory
BackendFactory adds a ratelimiting middleware wrapping the internal factory
func ConfigGetter ¶
func ConfigGetter(e config.ExtraConfig) interface{}
ConfigGetter implements the config.ConfigGetter interface. It parses the extra config for the rate adapter and returns a ZeroCfg if something goes wrong.
func NewMiddleware ¶
func NewMiddleware(remote *config.Backend) proxy.Middleware
NewMiddleware builds a middleware based on the extra config params or fallbacks to the next proxy