(next http.Handler)
| 750 | } |
| 751 | |
| 752 | func (s *Server) withRequestLoggingAndMetrics(next http.Handler) http.Handler { |
| 753 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 754 | start := time.Now() |
| 755 | rec := &statusRecorder{ResponseWriter: w, statusCode: http.StatusOK} |
| 756 | next.ServeHTTP(rec, r) |
| 757 | |
| 758 | statusCode := rec.statusCode |
| 759 | s.recordHTTPMetric(r.URL.Path, r.Method, statusCode) |
| 760 | log.Printf("event=http_request path=%s method=%s status=%d latency_ms=%d", r.URL.Path, r.Method, statusCode, time.Since(start).Milliseconds()) |
| 761 | }) |
| 762 | } |
| 763 | |
| 764 | func (s *Server) recordHTTPMetric(path, method string, statusCode int) { |
| 765 | if s.httpReqCounter == nil { |
no test coverage detected