proxy

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package proxy provides a rate-limit proxy middleware.

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 ratelimitproxy "github.com/davron112/krakend-ratelimit/v3/proxy"

...

var p proxy.Proxy
var backend *config.Backend

...

p = ratelimitproxy.NewMiddleware(backend)(p)

...

The ratelimit package provides an efficient token bucket implementation. See http://en.wikipedia.org/wiki/Token_bucket for more details.

Index

Constants

View Source
const Namespace = "qos/ratelimit/proxy"

Namespace is the key to use to store and access the custom config data for the proxy

Variables

View Source
var (
	ErrNoExtraCfg    = errors.New("no extra config")
	ErrWrongExtraCfg = errors.New("wrong extra config")
)
View Source
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

func NewMiddleware(logger logging.Logger, 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 uint64
}

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.

Jump to

Keyboard shortcuts

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