chain

package
v3.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

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.

func (Chain) Add

func (c Chain) Add(m Middleware) Chain

Add adds a middleware to a Chain

func (Chain) Resolve

func (c Chain) Resolve(routeHandler Handler) http.HandlerFunc

Resolve converts the Chain to a normal HTTP handler and returns it

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

type Middleware func(Handler) Handler

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.

Jump to

Keyboard shortcuts

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