Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type IPRateLimiter ¶ added in v1.12.0
type IPRateLimiter struct {
// contains filtered or unexported fields
}
IPRateLimiter manages rate limiters for individual IP addresses.
func NewIPRateLimiter ¶ added in v1.12.0
func NewIPRateLimiter(r rate.Limit, b int) *IPRateLimiter
NewIPRateLimiter creates a new IPRateLimiter with the specified rate and burst. r: Number of tokens per second. b: Maximum burst size.
func (*IPRateLimiter) AddIP ¶ added in v1.12.0
func (i *IPRateLimiter) AddIP(ip string) *rate.Limiter
AddIP adds a new limiter for the given IP address.
func (*IPRateLimiter) GetLimiter ¶ added in v1.12.0
func (i *IPRateLimiter) GetLimiter(ip string) *rate.Limiter
GetLimiter returns the rate limiter for the given IP address. If no limiter exists for the IP, it creates a new one.
func (*IPRateLimiter) Middleware ¶ added in v1.12.0
func (i *IPRateLimiter) Middleware() gin.HandlerFunc
Middleware returns a gin middleware that performs rate limiting based on the client's IP address.
type LimitCounter ¶
type LimitCounter struct {
// MaxConnections defines the maximum number of concurrent connections allowed.
MaxConnections int32
// CurrentConnections tracks the current number of active connections in the LimitCounter middleware.
CurrentConnections int32
}
LimitCounter tracks the current number of active connections and limits them based on a specified maximum.
func NewLimitCounter ¶
func NewLimitCounter(maxConnections int32) *LimitCounter
NewLimitCounter creates a new LimitCounter instance with the specified maximum number of concurrent connections.
func (*LimitCounter) Middleware ¶
func (lc *LimitCounter) Middleware() gin.HandlerFunc
Middleware limits the number of concurrent connections handled by the server based on MaxConnections. It is context-aware and prioritizes certain types of requests.
func (*LimitCounter) MiddlewareWithLogger ¶ added in v1.12.0
func (lc *LimitCounter) MiddlewareWithLogger(logger *slog.Logger) gin.HandlerFunc
MiddlewareWithLogger is the logger-injected variant of Middleware.