ratelimit

package
v1.20.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ratelimit implements the types.RateLimit interface for limiting access to resources shared service wide.

Index

Constants

View Source
const (
	TypeLocal = "local"
)

String constants representing each ratelimit type.

Variables

View Source
var Constructors = map[string]TypeSpec{}

Constructors is a map of all cache types with their specs.

Functions

func Descriptions

func Descriptions() string

Descriptions returns a formatted string of descriptions for each type.

func New

func New(
	conf Config,
	mgr types.Manager,
	log log.Modular,
	stats metrics.Type,
) (types.RateLimit, error)

New creates a rate limit type based on an rate limit configuration.

func NewLocal

func NewLocal(
	conf Config,
	mgr types.Manager,
	logger log.Modular,
	stats metrics.Type,
) (types.RateLimit, error)

NewLocal creates a local rate limit from a configuration struct. This type is safe to share and call from parallel goroutines.

func SanitiseConfig

func SanitiseConfig(conf Config) (interface{}, error)

SanitiseConfig creates a sanitised version of a config.

Types

type Config

type Config struct {
	Type  string      `json:"type" yaml:"type"`
	Local LocalConfig `json:"local" yaml:"local"`
}

Config is the all encompassing configuration struct for all cache types.

func NewConfig

func NewConfig() Config

NewConfig returns a configuration struct fully populated with default values.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing configs that are in a map or slice the default values are still applied.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing configs that are in a map or slice the default values are still applied.

type Local

type Local struct {
	// contains filtered or unexported fields
}

Local is a structure that tracks a rate limit, it can be shared across parallel processes in order to maintain a maximum rate of a protected resource.

func (*Local) Access

func (r *Local) Access() (time.Duration, error)

Access the rate limited resource. Returns a duration or an error if the rate limit check fails. The returned duration is either zero (meaning the resource can be accessed) or a reasonable length of time to wait before requesting again.

type LocalConfig

type LocalConfig struct {
	Count    int    `json:"count" yaml:"count"`
	Interval string `json:"interval" yaml:"interval"`
}

LocalConfig is a config struct containing rate limit fields for a local rate limit.

func NewLocalConfig

func NewLocalConfig() LocalConfig

NewLocalConfig returns a local rate limit configuration struct with default values.

type TypeSpec

type TypeSpec struct {
	// contains filtered or unexported fields
}

TypeSpec is a constructor and a usage description for each ratelimit type.

Jump to

Keyboard shortcuts

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