middleware

package
v0.0.0-...-f088481 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimitMiddleware

type RateLimitMiddleware struct {
	// contains filtered or unexported fields
}

RateLimitMiddleware is a http middleware for applying rate limit to an API. If the limit is exceeded, a status code 429 is returned. If an error is encountered while checking the limit, a status code 500 is returned. It also set the headers with rate limit information such as limit, retry after, and reset after. Ref: https://tools.ietf.org/id/draft-polli-ratelimit-headers-00.html

func NewRateLimiterMiddleware

func NewRateLimiterMiddleware(limiter ratelimiter.RateLimiter, clock clock.Clock) *RateLimitMiddleware

NewRateLimiterMiddleware instantiates a new rate limiter middleware

func (*RateLimitMiddleware) AttachRateLimitMiddleware

func (m *RateLimitMiddleware) AttachRateLimitMiddleware(next http.Handler) http.Handler

AttachRateLimitMiddleware wraps the passed http handler with a rate limiter middleware. The passed handler is only called if the rate limit threshold has not exceeded yet.

Jump to

Keyboard shortcuts

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