middleware

package
v0.0.0-...-3af2afe Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey = "reqID"

Key to use when setting the request ID.

Variables

This section is empty.

Functions

func GetReqID

func GetReqID(req *restful.Request) string

GetReqID returns a request ID from the given context if one is present. Returns the empty string if a request ID cannot be found.

func Logger

func Logger(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. When standard output is a TTY, Logger will print in color, otherwise it will print in black and white.

Logger prints a request ID if one is provided.

Logger has been designed explicitly to be Good Enough for use in small applications and for people just getting started with Goji. It is expected that applications will eventually outgrow this middleware and replace it with a custom request logger, such as one that produces machine-parseable output, outputs logs to a different service (e.g., syslog), or formats lines like those printed elsewhere in the application.

func Recoverer

func Recoverer(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible.

Recoverer prints a request ID if one is provided.

func RequestID

func RequestID(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

RequestID is a middleware that injects a request ID into the context of each request. A request ID is a string of the form "host.example.com/random-0001", where "random" is a base62 random string that uniquely identifies this go process, and where the last number is an atomically incremented request counter.

Types

This section is empty.

Jump to

Keyboard shortcuts

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