proxy

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 5 Imported by: 2

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": {
		"maxRate": 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

View Source
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

View Source
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

Types

type Config

type Config struct {
	MaxRate  float64
	Capacity int64
}

Config is the custom config struct containing the params for the limiter

Jump to

Keyboard shortcuts

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