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