middleware

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 8 Imported by: 3

README

func(http.Handler) http.Handler

Go Reference Codebeat Score

General Middleware

  • NOOP does nothing

Content Negotiation

  • AcceptMiddleware() alters the Accept header so only a given set is passed to the next handler in the chain

Error Handling Middleware

  • WithErrorHandlerMiddleware()

Special Handlers

  • HTTPSRedirectHandler a handler that will redirect to https if non-https, or return 404 already https

Error Handlers

we define an ErrorHandler as a function like:

func (http.ResponseWriter, *http.Request, error)

WithErrorHandler() and ErrorHandler() add and read the context for such handler

Documentation

Overview

Package middleware provices standard http middleware modules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptMiddleware added in v0.2.1

func AcceptMiddleware(supported ...string) func(http.Handler) http.Handler

AcceptMiddleware filters the Accept header to only include those

func NOOP added in v0.2.1

func NOOP(next http.Handler) http.Handler

NOOP is a middleware that doesn't do anything

func NewHTTPSRedirectHandler

func NewHTTPSRedirectHandler(port int) http.Handler

NewHTTPSRedirectHandler creates a new automatic redirect to HTTPS handler

func WithErrorHandler

func WithErrorHandler(ctx context.Context, eh ErrorHandlerFunc) context.Context

WithErrorHandler attaches an ErrorHandler function to a context for later retrieval

func WithErrorHandlerMiddleware

func WithErrorHandlerMiddleware(eh ErrorHandlerFunc) func(http.Handler) http.Handler

WithErrorHandlerMiddleware returns a middleware that attaches a given ErrorHandler to their contexts

Types

type ErrorHandlerFunc

type ErrorHandlerFunc = web.ErrorHandlerFunc

ErrorHandlerFunc is the signature of a function used as ErrorHandler

func ErrorHandler

func ErrorHandler(ctx context.Context) (ErrorHandlerFunc, bool)

ErrorHandler attempts to pull an ErrorHandler from the context.Context

type HTTPSRedirectHandler

type HTTPSRedirectHandler struct {
	Port int
}

HTTPSRedirectHandler provides an automatic redirect to HTTPS

func (*HTTPSRedirectHandler) ServeHTTP

func (h *HTTPSRedirectHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Directories

Path Synopsis
Package internal provides helpers for middleware implementations
Package internal provides helpers for middleware implementations

Jump to

Keyboard shortcuts

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