ratelimiter

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package ratelimiter provides basic rate limiting functionality as a with middeware.

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimitExceeded = errors.New("rate limit exceeded, please try again later")

ErrRateLimitExceeded happens when the connection was denied due to the rate limit being exceeded.

Functions

func Middleware

func Middleware(limiter RateLimiter) wish.Middleware

Middleware provides a new rate limiting Middleware.

Types

type RateLimiter

type RateLimiter interface {
	Allow(s ssh.Session) error
}

RateLimiter implementations should check if a given session is allowed to proceed or not, returning an error if they aren't. Its up to the implementation to handle what identifies an session as well as the implementation details of these limits.

func NewRateLimiter

func NewRateLimiter(r rate.Limit, burst int, maxEntries int) RateLimiter

NewRateLimiter returns a new RateLimiter that allows events up to rate rate, permits bursts of at most burst tokens and keeps a cache of maxEntries limiters.

Internally, it creates a LRU Cache of *rate.Limiter, in which the key is the remote IP address.

Jump to

Keyboard shortcuts

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