Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain represents a "chain" of middlewares through which a request can be threaded. Each middleware can modify the request/response and is responsible for calling the next middleware in the chain. The errorHandler is the last middleware in the chain, and converts it from a chain.Handler to a http.HandlerFunc.
func New ¶
func New(errorHandler TerminatingMiddleware) Chain
New constructs an empty Chain. You must provide a top level error handler to consume any errors raised from the chain.
type Handler ¶
type Handler func(http.ResponseWriter, *http.Request) error
Handler is like http.HandlerFunc, but returns an error indicating a failure during process the request. This can be used for cases when the application wishes to serve a 500 Internal Server Error.
type Middleware ¶
Middleware is a function that takes a Handler and returns a Handler It describes a transformation on the request/response Middleware can short-circuit the chain by not calling the passed in handler.
type TerminatingMiddleware ¶
type TerminatingMiddleware func(Handler) http.HandlerFunc
TerminatingMiddleware should sit at the top of the middleware chain, and converts a Handler (which returns an error) into a standard http.HandlerFunc which can be given to things like mux.Router.