throttler

package module
v0.0.0-...-cdadf55 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDeniedHandler is the default DeniedHandler for an
	// RateLimiter. It returns a 429 status code with a generic
	// message.
	DefaultDeniedHandler = func(ctx iris.Context) {
		ctx.StopWithText(http.StatusTooManyRequests, "limit exceeded")
	}

	// DefaultError is the default Error function for an RateLimiter.
	// It returns a 500 status code with a generic message.
	DefaultError = func(ctx iris.Context, err error) {
		ctx.StopWithError(http.StatusInternalServerError, err)
	}
)

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	// DeniedHandler is called if the request is disallowed. If it is
	// nil, the DefaultDeniedHandler variable is used.
	DeniedHandler iris.Handler

	// Error is called if the RateLimiter returns an error. If it is
	// nil, the DefaultErrorFunc is used.
	Error func(ctx iris.Context, err error)

	// Limiter is call for each request to determine whether the
	// request is permitted and update internal state. It must be set.
	RateLimiter throttled.RateLimiter

	// VaryBy is called for each request to generate a key for the
	// limiter. If it is nil, all requests use an empty string key.
	VaryBy interface {
		Key(*http.Request) string
	}
}

RateLimiter faciliates using a Limiter to limit HTTP requests.

func (*RateLimiter) RateLimit

func (t *RateLimiter) RateLimit(ctx iris.Context)

RateLimit is an Iris middleware that limits incoming requests. Requests that are not limited will be passed to the handler unchanged. Limited requests will be passed to the DeniedHandler. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset and Retry-After headers will be written to the response based on the values in the RateLimitResult.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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