Documentation
¶
Overview ¶
Package middleware provides middleware components for an HTTP router.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Authenticator ¶
type Authenticator struct { Signatory session.Signatory Deny http.HandlerFunc conversation.Error }
Authenticator provides a middleware function for authenticating requests using a signatory. Errors are put on to the Errors channel.
func (Authenticator) Authenticate ¶
func (a Authenticator) Authenticate(next http.Handler) http.Handler
Authenticate is middleware that will check a request is authenticated either via a JWT set in the Authorization header, or a secure cookie. Authenticated requests will have a session.Context type built from the claims stored in the authorisation token. This context is then stored in the session.
Unauthenticated requests will be passed to the Deny handler function. This defaults to the Unauthorised handler which returns StatusForbidden. Errors are put onto the Errors channel if one is set.
type RateLimiter ¶
type RateLimiter struct { ActionFunc func(r *http.Request) string Limiter session.Limiter conversation.Error }
A RateLimiter is used to rate limit some aspect of an HTTP request. The ActionFunc returns a string describing the action which is then applied to the underlying limiter.
func (*RateLimiter) Middleware ¶
func (r *RateLimiter) Middleware(next http.Handler) http.Handler
Middleware returns the RateLimiter middleware function.