limiter

package
v1.312.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingKey for limiter.
	ErrMissingKey = errors.New("missing key")
)
View Source
var Module = fx.Options(
	fx.Provide(New),
)

Module for fx.

Functions

func IsEnabled added in v1.166.0

func IsEnabled(cfg *Config) bool

IsEnabled limiter.

func RegisterKey added in v1.204.0

func RegisterKey(name string, fn KeyFunc)

RegisterKey with name and fn. Last register wins.

func Take added in v1.256.0

func Take(ctx context.Context, store limiter.Store, key KeyFunc) (bool, string, error)

Take from the store, returns if successful, info and error.

Types

type Config added in v1.166.0

type Config struct {
	Kind     string `yaml:"kind,omitempty" json:"kind,omitempty" toml:"kind,omitempty"`
	Interval string `yaml:"interval,omitempty" json:"interval,omitempty" toml:"interval,omitempty"`
	Tokens   uint64 `yaml:"tokens,omitempty" json:"tokens,omitempty" toml:"tokens,omitempty"`
}

Config for limiter.

type KeyFunc

type KeyFunc func(context.Context) meta.Valuer

KeyFunc for the limiter.

func New

func New(cfg *Config) (limiter.Store, KeyFunc, error)

New limiter.

Jump to

Keyboard shortcuts

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