summaryrefslogtreecommitdiff
path: root/srv/src/api/middleware.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-14 17:02:30 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-14 17:02:30 -0600
commite41ff2b897be24a894e75b850f1c06652cc034be (patch)
tree816cc87b789dd96b60f212311e161af1bb583e6a /srv/src/api/middleware.go
parent4c04177c05355ddb92d3d31a4c5cfbaa86555a13 (diff)
Implement index handler
This involved re-arranging how templates are being parsed, slightly.
Diffstat (limited to 'srv/src/api/middleware.go')
-rw-r--r--srv/src/api/middleware.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/srv/src/api/middleware.go b/srv/src/api/middleware.go
index 0b3eec7..fcd29b3 100644
--- a/srv/src/api/middleware.go
+++ b/srv/src/api/middleware.go
@@ -19,7 +19,7 @@ func addResponseHeaders(headers map[string]string, h http.Handler) http.Handler
})
}
-func annotateMiddleware(h http.Handler) http.Handler {
+func setLoggerMiddleware(logger *mlog.Logger, h http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
type reqInfoKey string
@@ -34,6 +34,7 @@ func annotateMiddleware(h http.Handler) http.Handler {
)
r = r.WithContext(ctx)
+ r = apiutil.SetRequestLogger(r, logger)
h.ServeHTTP(rw, r)
})
}
@@ -58,11 +59,9 @@ func (lrw *logResponseWriter) WriteHeader(statusCode int) {
lrw.ResponseWriter.WriteHeader(statusCode)
}
-func logMiddleware(logger *mlog.Logger, h http.Handler) http.Handler {
+func logReqMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
- r = apiutil.SetRequestLogger(r, logger)
-
lrw := newLogResponseWriter(rw)
started := time.Now()
@@ -77,7 +76,7 @@ func logMiddleware(logger *mlog.Logger, h http.Handler) http.Handler {
logCtxKey("response_code"), lrw.statusCode,
)
- logger.Info(ctx, "handled HTTP request")
+ apiutil.GetRequestLogger(r).Info(ctx, "handled HTTP request")
})
}