middleware

package
v0.0.0-...-a46f264 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package middleware implements a simple middleware pattern for HTTP handlers, along with implementation for some common middleware.

Index

Constants

View Source
const XSRFTokenPlaceholder = "$$XSRFTOKEN$$"

XSRFTokenPlaceholder should be used as the value for XSRF in rendered content. It is substituted for the actual token value by the XSRFProtect middleware.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

A Middleware is a func that wraps an http.Handler.

func Chain

func Chain(middlewares ...Middleware) Middleware

Chain creates a new Middleware that applies a sequence of Middlewares, so that they execute in the given order when handling an http request.

In other words, Chain(m1, m2)(handler) = m1(m2(handler)) The call chain is from outer to inner.

A similar pattern is used in e.g. github.com/justinas/alice: https://github.com/justinas/alice/blob/ce87934/chain.go#L45

Taken from: https://github.com/golang/pkgsite/blob/master/internal/middleware/middleware.go#L21

func Healthz

func Healthz(token string, fn func() error) Middleware

Healthz is a simple health check endpoint, which runs the given health function.

func SecureHeaders

func SecureHeaders() Middleware

SecureHeaders adds security-related headers to all responses.

func XSRFProtect

func XSRFProtect(key string) Middleware

XSRFProtect is a HTTP middlware adding XSRF/CSRF token protection for non-safe HTTP Methods.

Jump to

Keyboard shortcuts

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