Documentation ¶
Overview ¶
Package ratelimit implements the types.RateLimit interface for limiting access to resources shared service wide.
Index ¶
- Constants
- Variables
- func Descriptions() string
- func New(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (types.RateLimit, error)
- func NewLocal(conf Config, mgr types.Manager, logger log.Modular, stats metrics.Type) (types.RateLimit, error)
- func SanitiseConfig(conf Config) (interface{}, error)
- type Config
- type Local
- type LocalConfig
- type TypeSpec
Constants ¶
const (
TypeLocal = "local"
)
String constants representing each ratelimit type.
Variables ¶
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 ¶
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 ¶
UnmarshalJSON ensures that when parsing configs that are in a map or slice the default values are still applied.
func (*Config) UnmarshalYAML ¶
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.
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.