Documentation ¶
Overview ¶
Package middleware implements a simple middleware pattern for HTTP handlers, along with implementation for some common middleware.
Index ¶
Constants ¶
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 ¶
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.