Documentation ¶
Index ¶
- Constants
- func ContextRequestID(ctx context.Context) (reqID string)
- func Cors(origin string) web.Middleware
- func Errors(log logrus.FieldLogger) web.Middleware
- func Fields(err error) (map[string]interface{}, bool)
- func Logger(log logrus.FieldLogger) web.Middleware
- func Panics() web.Middleware
- func RequestID() web.Middleware
- func Response(err error) (interface{}, int, bool)
Constants ¶
const ( // RequestIDHeader is the name of the header used to transmit the request ID. RequestIDHeader = "X-Request-Id" // DefaultRequestIDLengthLimit is the default maximum length for the request ID header value. DefaultRequestIDLengthLimit = 128 )
Variables ¶
This section is empty.
Functions ¶
func ContextRequestID ¶
ContextRequestID extracts the Request ID from the context.
func Cors ¶
func Cors(origin string) web.Middleware
func Errors ¶
func Errors(log logrus.FieldLogger) web.Middleware
Errors handles errors coming out of the call chain. This middleware leverages a technique of opaque errors that allows to customize errors with behaviors without coupling them to a specific type. In this way, it's easier to create new errors compatible with the behavior used here.
func Fields ¶
Fields extracts fields to be logged together with the error. If the error does not implement the Fields behavior, it returns 'ok' to false and other parameters should be ignored.
func Logger ¶
func Logger(log logrus.FieldLogger) web.Middleware
Logger writes some information about the request to the logs. Influenced by https://github.com/zenazn/goji/blob/master/web/middleware/logger.go and https://github.com/ardanlabs/service/blob/master/business/web/v1/mid/logger.go
func Panics ¶
func Panics() web.Middleware
Panics recovers from panics and converts the panic to an error so it is handled in Errors.
func RequestID ¶
func RequestID() web.Middleware
RequestID is a middleware that injects a request ID into the context of each request. Retrieve it using ctx.Value(ReqIDKey). If the incoming request has a RequestIDHeader header then that value is used else a random value is generated.
Types ¶
This section is empty.