ratelimit

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FixWindowLimiter

type FixWindowLimiter struct {
	// contains filtered or unexported fields
}

FixWindowLimiter implements rate limiting using a fixed time window algorithm.

func NewFixWindowLimiter

func NewFixWindowLimiter(interval time.Duration, rate int64) *FixWindowLimiter

NewFixWindowLimiter creates a new FixWindowLimiter with the given interval and rate.

func (*FixWindowLimiter) LimitUnary

LimitUnary returns a grpc.UnaryServerInterceptor that imposes rate limiting based on the fixed window algorithm.

type FixWindowLimiterOptions

type FixWindowLimiterOptions func(l *FixWindowLimiter)

FixWindowLimiterOptions defines a function type for setting options on FixWindowLimiter.

func FixWindowMarkFailed

func FixWindowMarkFailed() FixWindowLimiterOptions

FixWindowMarkFailed provides an option to set the markFailedStrategy as the rejection strategy.

type LeakyBucketLimiter

type LeakyBucketLimiter struct {
	// contains filtered or unexported fields
}

LeakyBucketLimiter implements rate limiting using the leaky bucket algorithm.

func NewLeakyBucketLimiter

func NewLeakyBucketLimiter(interval time.Duration) *LeakyBucketLimiter

NewLeakyBucketLimiter initializes and returns a new LeakyBucketLimiter.

func (*LeakyBucketLimiter) Close

func (l *LeakyBucketLimiter) Close() error

Close stops the ticker and releases associated resources.

func (*LeakyBucketLimiter) LimitUnary

LimitUnary returns a grpc.UnaryServerInterceptor that imposes rate limiting based on the leaky bucket algorithm.

type LeakyBucketLimiterOptions

type LeakyBucketLimiterOptions func(l *LeakyBucketLimiter)

LeakyBucketLimiterOptions defines a function type for setting options on LeakyBucketLimiter.

func LeakyBucketMarkFailed

func LeakyBucketMarkFailed() LeakyBucketLimiterOptions

LeakyBucketMarkFailed provides an option to set the markFailedStrategy as the rejection strategy.

type Limiter

type Limiter interface {
	LimitUnary() grpc.UnaryServerInterceptor
}

type RedisFixWindowLimiter

type RedisFixWindowLimiter struct {
	// contains filtered or unexported fields
}

RedisFixWindowLimiter implements rate limiting using a fixed window approach with Redis.

func NewRedisFixWindowLimiter

func NewRedisFixWindowLimiter(client redis.Cmdable, service string, interval time.Duration, rate int) *RedisFixWindowLimiter

NewRedisFixWindowLimiter returns a new instance of RedisFixWindowLimiter with the provided configuration.

func (*RedisFixWindowLimiter) LimitUnary

LimitUnary returns a grpc.UnaryServerInterceptor that imposes rate limiting based on the fixed window mechanism.

type RedisFixWindowLimiterOptions

type RedisFixWindowLimiterOptions func(l *RedisFixWindowLimiter)

RedisFixWindowLimiterOptions defines the function signature for configuration options for RedisFixWindowLimiter.

func RedisFixWindowMarkFailed

func RedisFixWindowMarkFailed() RedisFixWindowLimiterOptions

RedisFixWindowMarkFailed provides an option to set the markFailedStrategy as the reject strategy.

type RedisSlideWindowLimiter

type RedisSlideWindowLimiter struct {
	// contains filtered or unexported fields
}

RedisSlideWindowLimiter implements rate limiting using a sliding window approach with redis.

func NewRedisSlideWindowLimiter

func NewRedisSlideWindowLimiter(client redis.Cmdable, service string, interval time.Duration, rate int) *RedisSlideWindowLimiter

NewRedisSlideWindowLimiter returns a new instance of RedisSlideWindowLimiter with the provided configuration.

func (*RedisSlideWindowLimiter) LimitUnary

LimitUnary returns a grpc.UnaryServerInterceptor that imposes rate limiting based on the sliding window mechanism.

type RedisSlideWindowLimiterOptions

type RedisSlideWindowLimiterOptions func(l *RedisSlideWindowLimiter)

RedisSlideWindowLimiterOptions defines the function signature for configuration options of RedisSlideWindowLimiter.

func RedisSlideWindowMarkFailed

func RedisSlideWindowMarkFailed() RedisSlideWindowLimiterOptions

RedisSlideWindowMarkFailed provides an option to set the markFailedStrategy as the reject strategy.

type SlideWindowLimiter

type SlideWindowLimiter struct {
	// contains filtered or unexported fields
}

SlideWindowLimiter implements rate limiting using a sliding window approach.

func NewSlideWindowLimiter

func NewSlideWindowLimiter(interval time.Duration, rate int) *SlideWindowLimiter

NewSlideWindowLimiter returns a new instance of SlideWindowLimiter with the specified interval and rate.

func (*SlideWindowLimiter) LimitUnary

LimitUnary returns a grpc.UnaryServerInterceptor that imposes rate limiting based on the sliding window mechanism.

type SlideWindowLimiterOptions

type SlideWindowLimiterOptions func(l *SlideWindowLimiter)

SlideWindowLimiterOptions defines the function signature for configuration options of SlideWindowLimiter.

func SlideWindowMarkFailed

func SlideWindowMarkFailed() SlideWindowLimiterOptions

SlideWindowMarkFailed provides an option to set the markFailedStrategy as the reject strategy.

type TokenBucketLimiter

type TokenBucketLimiter struct {
	// contains filtered or unexported fields
}

TokenBucketLimiter controls access to a resource by enforcing a rate limit using a token bucket strategy.

func NewTokenBucketLimiter

func NewTokenBucketLimiter(capacity int, interval time.Duration) *TokenBucketLimiter

NewTokenBucketLimiter constructs a new TokenBucketLimiter with the given capacity and token refill interval.

func (*TokenBucketLimiter) Close

func (l *TokenBucketLimiter) Close() error

Close cleanly stops the token refill and shuts down the limiter.

func (*TokenBucketLimiter) LimitUnary

LimitUnary returns a grpc.UnaryServerInterceptor that enforces the token bucket rate limiting.

type TokenBucketLimiterOptions

type TokenBucketLimiterOptions func(l *TokenBucketLimiter)

TokenBucketLimiterOptions defines the type for configuration options on the TokenBucketLimiter.

func TokenBucketMarkFailed

func TokenBucketMarkFailed() TokenBucketLimiterOptions

TokenBucketMarkFailed provides a configuration option to use the markFailedStrategy when a request is rejected.

Jump to

Keyboard shortcuts

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