proxy

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

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

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

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 int
}

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