middleware

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2015 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrorHandler = func(err error, w http.ResponseWriter, r *http.Request) {
	http.Error(w, err.Error(), http.StatusInternalServerError)
}

DefaultErrorHandler is an error handler that will respond with the error message and a 500 status.

View Source
var DefaultGenerator = context.Background

DefaultGenerator is the default context generator. Defaults to just use context.Background().

View Source
var StdoutLogger = stdLogger(os.Stdout)

StdoutLogger is a logger.Logger generator that generates a logger that writes to stdout.

Functions

func InsertLogger

func InsertLogger(h httpx.Handler, f func(context.Context, *http.Request) logger.Logger) httpx.Handler

InsertLogger returns an httpx.Handler middleware that will call f to generate a logger, then insert it into the context.

func LogTo

LogTo is an httpx middleware that wraps the handler to insert a logger and log the request to it.

Types

type Background

type Background struct {
	// Generate will be called to generate a context.Context for the
	// request.
	Generate func() context.Context
	// contains filtered or unexported fields
}

Background is middleware that implements the http.Handler interface to inject an initial context object. Use this as the entry point from an http.Handler server.

func BackgroundContext

func BackgroundContext(h httpx.Handler) *Background

func (*Background) ServeHTTP

func (h *Background) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

func (*Background) ServeHTTPContext

func (h *Background) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error

type Error

type Error struct {
	// ErrorHandler is a function that will be called when a handler returns
	// an error.
	ErrorHandler func(error, http.ResponseWriter, *http.Request)
	// contains filtered or unexported fields
}

Error is an httpx.Handler that will handle errors with an ErrorHandler.

func HandleError

func HandleError(h httpx.Handler, f func(error, http.ResponseWriter, *http.Request)) *Error

HandleError returns a new Error middleware that uses f as the ErrorHandler.

func NewError

func NewError(h httpx.Handler) *Error

func (*Error) ServeHTTPContext

func (h *Error) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error

ServeHTTPContext implements the httpx.Handler interface.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is middleware that logs the request details to the logger.Logger embedded within the context.

func Log

func Log(h httpx.Handler) *Logger

func (*Logger) ServeHTTPContext

func (h *Logger) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error

type NewRelicTracer

type NewRelicTracer struct {
	// contains filtered or unexported fields
}

func NewRelicTracing

func NewRelicTracing(h httpx.Handler, router *httpx.Router, tracer newrelic.TxTracer) *NewRelicTracer

func (*NewRelicTracer) ServeHTTPContext

func (h *NewRelicTracer) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error

type Recovery

type Recovery struct {
	// Reporter is a Reporter that will be inserted into the context. It
	// will also be used to report panics.
	reporter.Reporter
	// contains filtered or unexported fields
}

Recovery is a middleware that will recover from panics and return the error.

func Recover

func Recover(h httpx.Handler, r reporter.Reporter) *Recovery

func (*Recovery) ServeHTTPContext

func (h *Recovery) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) (err error)

ServeHTTPContext implements the httpx.Handler interface. It recovers from panics and returns an error for upstream middleware to handle.

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	// Status returns the status code of the response or 0 if the response has not been written.
	Status() int
}

ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response.

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) ResponseWriter

NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter

Jump to

Keyboard shortcuts

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