Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrRateLimitExceeded = errors.New("rate limit exceeded, please try again later")
Functions ¶
This section is empty.
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter limits the number of HTTP requests per second a user can make. It tracks limits for unauthenticated and authenticated users separately: - Authenticated requests are tracked by user ID or name. - Unauthenticated requests are tracked by IP address. - Admins are exempt from rate limiting.
func New ¶
func New(opts Options) (*RateLimiter, error)
func (*RateLimiter) ApplyLimit ¶
func (l *RateLimiter) ApplyLimit(u user.Info, rw http.ResponseWriter, req *http.Request) error
ApplyLimit applies the user's rate limit to the request, sets the rate limit headers, and returns a ErrRateLimitExceeded error if the limit has been exceeded. It returns nil if the user is exempt from rate limiting or if the user has not exceeded their limit.
Click to show internal directories.
Click to hide internal directories.