Documentation
¶
Index ¶
- type Config
- type FixedWindowLimiter
- type KeyFixedWindowCallConfig
- type KeyFixedWindowCallOption
- type KeyFixedWindowConfig
- type KeyFixedWindowLimiter
- func (kl *KeyFixedWindowLimiter) Acquire(ctx context.Context, key string, opts ...KeyFixedWindowCallOption) (bool, int64, error)
- func (kl *KeyFixedWindowLimiter) CurrentConcurrent(ctx context.Context, key string) (int64, error)
- func (kl *KeyFixedWindowLimiter) Release(ctx context.Context, key string) (int64, error)
- type KeyFixedWindowLimiterInterface
- type KeyFixedWindowOption
- type Limiter
- type LimiterConfig
- type LimiterOption
- type Option
- type PlanConfig
- type PlanLimiter
- func (pl *PlanLimiter) Allow(ctx context.Context, key string, model string, tokens int64, ...) (bool, *PlanUsage, error)
- func (pl *PlanLimiter) Refund(ctx context.Context, key string, model string, tokens int64, ...) (*PlanUsage, error)
- func (pl *PlanLimiter) Usage(ctx context.Context, key string, opts ...PlanOption) (*PlanUsage, error)
- type PlanLimiterInterface
- type PlanOption
- type PlanUsage
- type RedisLimiter
- type RedisLimiterInterface
- type XTokenBucket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
LimiterConfig
}
Config holds per-request configuration for Allow calls. These values override the defaults set by LimiterConfig at construction time.
type FixedWindowLimiter ¶
type FixedWindowLimiter struct {
// contains filtered or unexported fields
}
func NewFixedWindow ¶
func NewFixedWindow(concurrent int) *FixedWindowLimiter
func (*FixedWindowLimiter) Close ¶
func (l *FixedWindowLimiter) Close()
func (*FixedWindowLimiter) ReleaseToken ¶
func (l *FixedWindowLimiter) ReleaseToken()
func (*FixedWindowLimiter) TakeToken ¶
func (l *FixedWindowLimiter) TakeToken()
func (*FixedWindowLimiter) TakeTokenNonBlocking ¶
func (l *FixedWindowLimiter) TakeTokenNonBlocking() bool
func (*FixedWindowLimiter) TakeTokenWithTimeout ¶
func (l *FixedWindowLimiter) TakeTokenWithTimeout(timeout time.Duration) bool
func (*FixedWindowLimiter) Wait ¶
func (l *FixedWindowLimiter) Wait()
type KeyFixedWindowCallConfig ¶
type KeyFixedWindowCallConfig struct {
MaxConcurrent int64
}
type KeyFixedWindowCallOption ¶
type KeyFixedWindowCallOption func(*KeyFixedWindowCallConfig)
func WithMaxConcurrent ¶
func WithMaxConcurrent(m int64) KeyFixedWindowCallOption
type KeyFixedWindowConfig ¶
type KeyFixedWindowLimiter ¶
type KeyFixedWindowLimiter struct {
// contains filtered or unexported fields
}
func NewKeyFixedWindowLimiter ¶
func NewKeyFixedWindowLimiter(ctx context.Context, r redis.Cmdable, opts ...KeyFixedWindowOption) (*KeyFixedWindowLimiter, error)
func (*KeyFixedWindowLimiter) Acquire ¶
func (kl *KeyFixedWindowLimiter) Acquire(ctx context.Context, key string, opts ...KeyFixedWindowCallOption) (bool, int64, error)
func (*KeyFixedWindowLimiter) CurrentConcurrent ¶
CurrentConcurrent returns the approximate current concurrent count for the given key. The value may be stale immediately after reading due to concurrent Acquire/Release operations from other clients. Use this for monitoring and observability only.
type KeyFixedWindowOption ¶
type KeyFixedWindowOption func(*KeyFixedWindowConfig)
func WithDefaultExpiration ¶
func WithDefaultExpiration(d time.Duration) KeyFixedWindowOption
func WithDefaultMaxConcurrent ¶
func WithDefaultMaxConcurrent(m int64) KeyFixedWindowOption
type LimiterConfig ¶
LimiterConfig holds the default configuration for RedisLimiter construction. These values are used when Allow is called without explicit Option overrides.
type LimiterOption ¶
type LimiterOption func(*LimiterConfig)
LimiterOption configures default values at construction time.
func WithDefaultCapacity ¶
func WithDefaultCapacity(c int64) LimiterOption
func WithDefaultRate ¶
func WithDefaultRate(r int64) LimiterOption
func WithDefaultRequested ¶
func WithDefaultRequested(n int64) LimiterOption
type Option ¶
type Option func(*Config)
Option overrides parameters on a per-request basis.
func WithCapacity ¶
func WithRequested ¶
type PlanConfig ¶
type PlanLimiter ¶
type PlanLimiter struct {
// contains filtered or unexported fields
}
func NewPlanLimiter ¶
func NewPlanLimiter(ctx context.Context, r redis.Cmdable, opts ...PlanOption) (*PlanLimiter, error)
func (*PlanLimiter) Allow ¶
func (pl *PlanLimiter) Allow(ctx context.Context, key string, model string, tokens int64, opts ...PlanOption) (bool, *PlanUsage, error)
func (*PlanLimiter) Refund ¶
func (pl *PlanLimiter) Refund(ctx context.Context, key string, model string, tokens int64, opts ...PlanOption) (*PlanUsage, error)
func (*PlanLimiter) Usage ¶
func (pl *PlanLimiter) Usage(ctx context.Context, key string, opts ...PlanOption) (*PlanUsage, error)
type PlanLimiterInterface ¶
type PlanLimiterInterface interface {
Allow(ctx context.Context, key string, model string, tokens int64, opts ...PlanOption) (bool, *PlanUsage, error)
Refund(ctx context.Context, key string, model string, tokens int64, opts ...PlanOption) (*PlanUsage, error)
Usage(ctx context.Context, key string, opts ...PlanOption) (*PlanUsage, error)
}
type PlanOption ¶
type PlanOption func(*PlanConfig)
func WithPlanBucketSize ¶
func WithPlanBucketSize(bs time.Duration) PlanOption
func WithPlanBudget ¶
func WithPlanBudget(b int64) PlanOption
func WithPlanWeight ¶
func WithPlanWeight(w float64) PlanOption
func WithPlanWindow ¶
func WithPlanWindow(w time.Duration) PlanOption
type RedisLimiter ¶
type RedisLimiter struct {
// contains filtered or unexported fields
}
func NewRedisLimiter ¶
func NewRedisLimiter(ctx context.Context, r redis.Cmdable, opts ...LimiterOption) (*RedisLimiter, error)
NewRedisLimiter creates a new RedisLimiter instance. LimiterOption configures the default values used when Allow is called without explicit options. This is distinct from Option, which overrides parameters on a per-request basis.
type RedisLimiterInterface ¶
type RedisLimiterInterface interface {
Allow(ctx context.Context, key string, opts ...Option) (bool, error)
}
RedisLimiterInterface defines the interface for token bucket rate limiting.
type XTokenBucket ¶
type XTokenBucket struct {
// contains filtered or unexported fields
}
func NewXTokenBucket ¶
func NewXTokenBucket(qos, burst int) *XTokenBucket
func (*XTokenBucket) TakeToken ¶
func (x *XTokenBucket) TakeToken()
func (*XTokenBucket) TakeTokenNonBlocking ¶
func (x *XTokenBucket) TakeTokenNonBlocking() bool
func (*XTokenBucket) TakeTokenWithTimeout ¶
func (x *XTokenBucket) TakeTokenWithTimeout(timeout time.Duration) bool