ratelimit

package
v0.78.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ratelimit provides a rate limiting functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMiddleware

func NewMiddleware(c *Config) (m proxy.Middleware)

NewMiddleware returns middleware with rate limiting functionality. c must be valid.

Types

type Config

type Config struct {
	// Logger is used for logging in the ratelimit middleware. It must not be
	// nil.
	Logger *slog.Logger

	// AllowlistAddrs is a slice of IP addresses excluded from rate limiting.
	AllowlistAddrs netutil.SliceSubnetSet

	// Ratelimit is a maximum number of requests per second from a given IP.  It
	// must be positive.
	Ratelimit uint

	// SubnetLenIPv4 is a subnet length for IPv4 addresses used for rate
	// limiting requests.
	SubnetLenIPv4 uint

	// SubnetLenIPv6 is a subnet length for IPv6 addresses used for rate
	// limiting requests.
	SubnetLenIPv6 uint
}

Config is the configuration for the ratelimit middleware.

func (*Config) Validate

func (c *Config) Validate() (err error)

Validate implements the validate.Interface interface for *Config.

Jump to

Keyboard shortcuts

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