ratelimiter

package
v0.0.0-...-bc6e940 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MemRatelimiterCacheExpiration MemRatelimiter key
	MemRatelimiterCacheExpiration = time.Minute * 60
	// MemRatelimiterCacheCleanInterval MemRatelimiter
	MemRatelimiterCacheCleanInterval = time.Minute * 60
)

Functions

func DefaultGinLimitKey

func DefaultGinLimitKey(c *gin.Context) string

DefaultGinLimitKey returns the default gin limit key

func DefaultGinLimitedHandler

func DefaultGinLimitedHandler(c *gin.Context)

DefaultGinLimitedHandler 429

func GinMemRatelimiter

func GinMemRatelimiter(conf GinRatelimiterConfig, logger *logger.Logger) gin.HandlerFunc

GinMemRatelimiter return the gin rate limiter handler func

Types

type GinRatelimiterConfig

type GinRatelimiterConfig struct {
	// LimitKey
	LimitKey func(*gin.Context) string
	// LimitedHandler
	LimitedHandler func(*gin.Context)
	// TokenBucketConfig
	TokenBucketConfig func(*gin.Context) (time.Duration, int)
}

GinRatelimiterConfig Gin Ratelimiter

type MemRatelimiter

type MemRatelimiter struct {
	*rate.Limiter
	*cache.Cache
	Expire time.Duration
	// contains filtered or unexported fields
}

MemRatelimiter limiter

func NewMemRatelimiter

func NewMemRatelimiter(logger *logger.Logger) *MemRatelimiter

NewMemRatelimiter mem limiter

func (*MemRatelimiter) Allow

func (r *MemRatelimiter) Allow(ctx context.Context, key string, tokenFillInterval time.Duration, bucketSize int) bool

Allow time/rate & token bucket key tokenFillInterval Token bucketSize Token

Jump to

Keyboard shortcuts

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