Documentation
¶
Index ¶
- Constants
- func Provider(options ...ProviderOption) runaprovider.Provider
- type Algorithm
- type Driver
- type DriverOption
- type DriverOptions
- type Info
- type KeySource
- type KeySourceFunc
- type Limiter
- type Option
- func Burst(value int) Option
- func FixedWindow(limit int, window time.Duration) Option
- func Key(sources ...KeySource) Option
- func Meta(key string, value any) Option
- func SlidingWindow(limit int, window time.Duration) Option
- func TokenBucket(limit int, window time.Duration) Option
- func Use(name string) Option
- type ProviderOption
- type Registry
- func (registry *Registry) Close(ctx context.Context) error
- func (registry *Registry) Config(store *config.Store)
- func (registry *Registry) Info() []Info
- func (registry *Registry) Key(name string, source KeySource)
- func (registry *Registry) MustOf(name string) Limiter
- func (registry *Registry) Of(name string) (Limiter, error)
- func (registry *Registry) Rate(name string, options ...Option)
- func (registry *Registry) RegisterDriver(name string, driver Driver)
- func (registry *Registry) Rule(name string) (Rule, bool)
- func (registry *Registry) Shutdown(ctx context.Context) error
- type Result
- type Rule
Constants ¶
View Source
const ( DefaultDriver = "memory" DefaultName = "api" API = "api" Login = "login" Admin = "admin" SMS = "sms" )
Variables ¶
This section is empty.
Functions ¶
func Provider ¶
func Provider(options ...ProviderOption) runaprovider.Provider
Types ¶
type Driver ¶
type Driver interface {
Name() string
Allow(ctx context.Context, rule Rule, key string) (Result, error)
Reset(ctx context.Context, rule Rule, key string) error
Close(ctx context.Context) error
}
Driver handles limit primitives.
func MemoryDriver ¶
func MemoryDriver(options ...DriverOption) Driver
MemoryDriver creates a single-process rate driver.
type DriverOption ¶
type DriverOption interface{ ApplyDriver(*DriverOptions) }
DriverOption configures driver stores.
func DriverMeta ¶
func DriverMeta(key string, value any) DriverOption
DriverMeta stores arbitrary driver metadata.
type DriverOptions ¶
DriverOptions stores driver metadata.
type Info ¶
type Info struct {
Name string
Driver string
Algorithm Algorithm
Limit int
Window time.Duration
Burst int
Default bool
Meta core.Map
}
Info describes one configured limiter.
type KeySource ¶
KeySource resolves one key part outside the core package.
type KeySourceFunc ¶
KeySourceFunc adapts a function to KeySource.
func (KeySourceFunc) Name ¶
func (source KeySourceFunc) Name() string
func (KeySourceFunc) Value ¶
func (source KeySourceFunc) Value(ctx any) string
type Limiter ¶
type Limiter interface {
Allow(ctx context.Context, keys ...string) (Result, error)
Reset(ctx context.Context, keys ...string) error
}
Limiter is a named limiter.
type Option ¶
type Option interface{ ApplyRate(*Rule) }
Option configures a named limiter.
func FixedWindow ¶
FixedWindowRule configures fixed window limit.
func SlidingWindow ¶
SlidingWindowRule configures sliding window limit.
func TokenBucket ¶
TokenBucket configures token bucket limit.
type ProviderOption ¶
type ProviderOption func(*provider)
func RegisterDriver ¶
func RegisterDriver(name string, driver Driver) ProviderOption
func RegisterKey ¶
func RegisterKey(name string, source KeySource) ProviderOption
func RegisterLimiter ¶
func RegisterLimiter(name string, options ...Option) ProviderOption
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) RegisterDriver ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.