backendratelimit

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfigStructure

func NewConfigStructure() (element.Sections, error)

NewConfigStructure global configuration structure for this package. Used in frontend (to display the user all the settings) and in backend (scope checks and default values). See the source code of this function for the overall available sections, groups and fields.

Types

type Configuration

type Configuration struct {
	*ratelimit.OptionFactories

	// Disabled set to true to disable the rate limiting.
	//
	// Path: net/ratelimit/disabled
	Disabled cfgmodel.Bool

	// Burst defines the number of requests that will be allowed to
	// exceed the rate in a single burst and must be greater than or equal to
	// zero.
	//
	// Path: net/ratelimit/burst
	Burst cfgmodel.Int

	// Requests number of requests allowed per time period
	//
	// Path: net/ratelimit/requests
	Requests cfgmodel.Int

	// Duration per second (s), minute (i), hour (h), day (d)
	//
	// Path: net/ratelimit/duration
	Duration cfgmodel.Str

	// GCRAName sets the name which GCRA can be used. The GCRA must be
	// registered prior to calling the middleware handler. The name is usually
	// the package name. For example net/ratelimit/memstore or
	// net/ratelimit/redigostore. Leaving this configuration value empty or
	// setting a not registered name causes the middleware handler to panic.
	//
	// Path: net/ratelimit_storage/gcra_name
	GCRAName cfgmodel.Str

	// StorageGCRAMaxMemoryKeys If maxKeys > 0 (enabled), the number of
	// different keys is restricted to the specified amount. In this case, it
	// uses an LRU algorithm to evict older keys to make room for newer ones.
	//
	// Path: net/ratelimit_storage/enable_gcra_memory
	StorageGCRAMaxMemoryKeys cfgmodel.Int

	// StorageGCRARedis a valid Redis URL enables Redis as GCRA key
	// storage. URLs should follow the draft IANA specification for the scheme
	// (https://www.iana.org/assignments/uri-schemes/prov/redis).
	//
	//
	// For example:
	// 		redis://localhost:6379/3
	// 		redis://:6380/0 => connects to localhost:6380
	// 		redis:// => connects to localhost:6379 with DB 0
	// 		redis://empty:myPassword@clusterName.xxxxxx.0001.usw2.cache.amazonaws.com:6379/0
	//
	// Path: net/ratelimit_storage/enable_gcra_redis
	StorageGCRARedis cfgmodel.Str
}

Configuration just exported for the sake of documentation. See fields for more information. Please call the New() function for creating a new Backend object. Only the New() function will set the paths to the fields.

func New

func New(cfgStruct element.Sections, opts ...cfgmodel.Option) *Configuration

New initializes the backend configuration models containing the cfgpath.Route variable to the appropriate entries in the storage. The argument Sections and opts will be applied to all models.

func (*Configuration) PrepareOptionFactory

func (be *Configuration) PrepareOptionFactory() ratelimit.OptionFactoryFunc

PrepareOptionFactory creates a closure around the type Backend. The closure will be used during a scoped request to figure out the configuration depending on the incoming scope. An option array will be returned by the closure.

Jump to

Keyboard shortcuts

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