ctxh

package
v1.6.2-tectonic.1-rc.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(h ContextHandler) http.Handler

NewHandler returns an http.Handler which wraps the given ContextHandler and creates a background context.Context.

func NewHandlerWithContext

func NewHandlerWithContext(ctx context.Context, h ContextHandler) http.Handler

NewHandlerWithContext returns an http.Handler which wraps the given context and ContextHandler.

Types

type AppError

type AppError struct {
	Error   error
	Message string
	Code    int
}

AppError bundles error data and should only be used as a return type for ContextHandlerFuncWithError functions.

func NewAppError

func NewAppError(err error, message string, code int) *AppError

NewAppError returns a new AppError.

type ContextHandler

type ContextHandler interface {
	ServeHTTP(context.Context, http.ResponseWriter, *http.Request)
}

ContextHandler defines a handler which receives a passed context.Context with the standard ResponseWriter and Request.

type ContextHandlerFunc

type ContextHandlerFunc func(context.Context, http.ResponseWriter, *http.Request)

ContextHandlerFunc type is an adapter to allow the use of an ordinary function as a ContextHandler. If f is a function with the correct signature, ContextHandlerFunc(f) is a ContextHandler that calls f.

func (ContextHandlerFunc) ServeHTTP

func (f ContextHandlerFunc) ServeHTTP(ctx context.Context, w http.ResponseWriter, req *http.Request)

ServeHTTP calls the function f(ctx, w, req).

type ContextHandlerFuncWithError

type ContextHandlerFuncWithError func(context.Context, http.ResponseWriter, *http.Request) *AppError

ContextHandlerFuncWithError is an adapter func to allow a context handler function which returns an AppError to be used as a ContextHandler. If f is a function with the correct signature, ContextHandlerFuncWithError(f) is a ContextHandler which calls f and writes the AppError if non-nil.

func (ContextHandlerFuncWithError) ServeHTTP

Jump to

Keyboard shortcuts

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