Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Impl ¶
type Impl struct {
// contains filtered or unexported fields
}
Using sync.Map for safe concurrent access.
func (*Impl) ShouldRateLimit ¶
shouldRateLimit returns true if the request should be rate limited, and the reason why. It returns false if the request should not be rate limited.
You should generally use it like so:
shouldRateLimit, reason := rateLimiter.shouldRateLimit(r) if (shouldRateLimit) { w.WriteHeader(http.StatusTooManyRequests) w.Write([]byte("Rate limit exceeded. reason:" + reason)) return } next.ServeHTTP(w, r)
The rate limiting logic is different per API since this server is for educational purposes.
type RateLimiter ¶
type RateLimiter interface { Middleware(next http.Handler) http.Handler // This is an internal func, exporting just to make testing easy. ShouldRateLimit(r *http.Request) (bool, string, error) }
func NewRateLimiter ¶
func NewRateLimiter( logger zerolog.Logger, config Config, ) RateLimiter
Click to show internal directories.
Click to hide internal directories.