limiter

package
v0.0.0-...-24b49fa Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FixedWindow = iota
	SlidingWindow
	TokenBucket
	LeakyBucket
)

Variables

This section is empty.

Functions

func NewFixedWindowLimiter

func NewFixedWindowLimiter(options *FixedWindowOptions) *fixedWindowLimiter

func NewLeakyBucketLimiter

func NewLeakyBucketLimiter(options *LeakyBucketOptions) *leakyBucketLimiter

func NewRedisFixedWindowLimiter

func NewRedisFixedWindowLimiter(options *RedisFixedWindowOptions) *redisFixedWindowLimiter

func NewRedisLeakyBucketLimiter

func NewRedisLeakyBucketLimiter(options *RedisLeakyBucketOptions) *redisLeakyBucketLimiter

func NewRedisSlidingWindowLimiter

func NewRedisSlidingWindowLimiter(options *RedisSlidingWindowOptions) *redisSlidingWindowLimiter

func NewRedisTokenBucketLimiter

func NewRedisTokenBucketLimiter(options *RedisTokenBucketOptions) *redisTokenBucketLimiter

func NewSlidingWindowLimiter

func NewSlidingWindowLimiter(options *SlidingWindowOptions) *slidingWindowLimiter

func NewTokenBucketLimiter

func NewTokenBucketLimiter(options *TokenBucketOptions) *tokenBucketLimiter

Types

type FixedWindowOptions

type FixedWindowOptions struct {
	Prefix   string
	Interval time.Duration
	Limit    int
}

type LeakyBucketOptions

type LeakyBucketOptions struct {
	Prefix string

	Capacity int

	// to calculate rate
	Limit    int
	Interval time.Duration
}

type Limiter

type Limiter interface {
	AcceptConnection(ctx context.Context, biz string) bool
}

func NewLimiter

func NewLimiter(options any) Limiter

type RedisFixedWindowOptions

type RedisFixedWindowOptions struct {
	RedisClient redis.Cmdable
	Prefix      string
	Interval    time.Duration
	Limit       int
}

type RedisLeakyBucketOptions

type RedisLeakyBucketOptions struct {
	RedisClient redis.Cmdable
	Prefix      string

	Capacity int

	// to calculate rate
	Limit    int
	Interval time.Duration
}

type RedisSlidingWindowOptions

type RedisSlidingWindowOptions struct {
	RedisClient   redis.Cmdable
	Interval      time.Duration
	Prefix        string
	WindowsAmount int
	Limit         int
}

type RedisTokenBucketOptions

type RedisTokenBucketOptions struct {
	RedisClient redis.Cmdable
	Prefix      string

	Capacity int

	// to calculate rate
	ReleaseAmount int
	Interval      time.Duration
}

type SlidingWindowOptions

type SlidingWindowOptions struct {
	Prefix        string
	Interval      time.Duration
	WindowsAmount int
	Limit         int
}

type TokenBucketOptions

type TokenBucketOptions struct {
	Prefix string

	Capacity int

	// to calculate rate
	RelaseAmount int
	Interval     time.Duration
}

Directories

Path Synopsis
Package limitermocks is a generated GoMock package.
Package limitermocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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