middleware

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package middleware provides middleware components for an HTTP router.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Source

func Source(r *http.Request) string

Source rate limiter which will limit requests from the same remote address.

Example
package main

import (
	"bitbucket.org/idomdavis/gohttp/middleware"
)

func main() {
	_ = middleware.RateLimiter{ActionFunc: middleware.Source}
}
Output:

func User

func User(r *http.Request) string

User rate limiter which will limit requests with the same basic auth user set.

Example
package main

import (
	"bitbucket.org/idomdavis/gohttp/middleware"
)

func main() {
	_ = middleware.RateLimiter{ActionFunc: middleware.User}
}
Output:

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.

Jump to

Keyboard shortcuts

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