middleware

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const CtxRequestIDKey = ctxRequestID(iota)
View Source
const CtxRequestPathKey = ctxRequestPath(iota)

Variables

This section is empty.

Functions

func CtxRequestID

func CtxRequestID(r *http.Request) string

CtxRequestID retrieves the `X-Request-Id` from the current request `context`.

func CtxRequestPath

func CtxRequestPath(r *http.Request) string

CtxRequestPath retrieves the request path from the current request `context`.

func PanicRecovery

func PanicRecovery(handler http.Handler) http.Handler

PanicRecovery catches all `panic` calls in order to prevent HTTP server from going down and returns a standardised `500 Internal Server Error` response.

func RequestID

func RequestID(h http.Handler) http.Handler

RequestID is a server level middleware and called on every request to handle `X-Request-Id` header. If the header already exists in the request, nothing else is done otherwise a new UUID V4 format is generated and added to request `context` as `X-Request-Id` header.

func RequestPath

func RequestPath(h http.Handler) http.Handler

RequestPath is a server level middleware and called on every request to construct request path as in `{method} {uri}` format and added to request `context`.

func Router

func Router(h http.HandlerFunc, middleware ...rtr) http.HandlerFunc

Router allows router level middleware chaining. The first middleware in the chain runs last. Server level middleware always take precedence over router level middleware.

func Server

func Server(h http.Handler, middleware ...srv) http.Handler

Server allows server level middleware chaining. The first middleware in the chain runs last. Server level middleware always take precedence over router level middleware.

Types

This section is empty.

Jump to

Keyboard shortcuts

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