Documentation ¶
Overview ¶
Package middleware contains various server middleware to help with requests, including logging, instrumentation, authentication, and debugging middleware.
Index ¶
- func Authenticator(unauthorized http.Handler) func(next http.Handler) http.Handler
- func Logger(log *zap.Logger) func(next http.Handler) http.Handler
- func NewRelicChiRouter(nr newrelic.Application) func(next http.Handler) http.Handler
- func TraceID(next http.Handler) http.Handler
- func User(next http.Handler) http.Handler
- func Version(v string) func(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authenticator ¶
Authenticator is used to verify a valid token is on the request. The param unauthorized should be a request handler to render your 401 response. If it is nil, a simple default response will be written.
func Logger ¶
Logger middleware logs each request and adds the logger to the request context for use in request handlers.
func NewRelicChiRouter ¶
NewRelicChiRouter will start a newrelic transaction for the request. It will name the transaction to match the chi route. It will also add custom attributes to the transaction, such as the trace id, any url parameters, and query string parameters. These attributes make it easy to tie your New Relic traces to logs. This middleware can be used in place of using newrelic.WrapHandleFunc everywhere.
func TraceID ¶
TraceID tries to read the X-Trace-Id request header, and if empty, creates a new traceID to use. This traceID will be added to the response X-Trace-Id header and to the request context.
Types ¶
This section is empty.