Documentation
¶
Index ¶
- Variables
- func InsertLogger(h httpx.Handler, f func(context.Context, *http.Request) logger.Logger) httpx.Handler
- func LogTo(h httpx.Handler, f func(context.Context, *http.Request) logger.Logger) httpx.Handler
- type Background
- type Error
- type Logger
- type NewRelicTracer
- type Recovery
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
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.
var DefaultGenerator = context.Background
DefaultGenerator is the default context generator. Defaults to just use context.Background().
var StdoutLogger = stdLogger(os.Stdout)
StdoutLogger is a logger.Logger generator that generates a logger that writes to stdout.
Functions ¶
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 ¶
HandleError returns a new Error middleware that uses f as the ErrorHandler.
func (*Error) ServeHTTPContext ¶
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 (*Logger) ServeHTTPContext ¶
type NewRelicTracer ¶
type NewRelicTracer struct {
// contains filtered or unexported fields
}
func NewRelicTracing ¶
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 (*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