WithMonitoring wraps RouteHandler with monitoring handling.
(h RouteHandler)
| 14 | |
| 15 | // WithMonitoring wraps RouteHandler with monitoring handling. |
| 16 | func (r *Router) WithMonitoring(h RouteHandler) RouteHandler { |
| 17 | if !r.monitoring.Enabled() { |
| 18 | return h |
| 19 | } |
| 20 | |
| 21 | return func(reqID string, rw ResponseWriter, req *http.Request) *Error { |
| 22 | ctx, cancel, newRw := r.monitoring.StartRequest(req.Context(), rw.HTTPResponseWriter(), req) |
| 23 | defer cancel() |
| 24 | |
| 25 | // Replace rw.ResponseWriter with new one returned from monitoring |
| 26 | rw.SetHTTPResponseWriter(newRw) |
| 27 | |
| 28 | return h(reqID, rw, req.WithContext(ctx)) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // WithCORS wraps RouteHandler with CORS handling |
| 33 | func (r *Router) WithCORS(h RouteHandler) RouteHandler { |
nothing calls this directly
no test coverage detected