From fbce0c006cbd5d172e3ba6cbb6f8325856388e83 Mon Sep 17 00:00:00 2001 From: lbenedar Date: Thu, 5 Mar 2026 13:04:59 +0300 Subject: [PATCH] ch6.3 --- cmd/web/middleware.go | 8 ++++++++ cmd/web/routes.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/web/middleware.go b/cmd/web/middleware.go index c35458e..df6000e 100644 --- a/cmd/web/middleware.go +++ b/cmd/web/middleware.go @@ -14,3 +14,11 @@ func secureHeaders(next http.Handler) http.Handler { next.ServeHTTP(w, r) }) } + +func (app *application) logRequest(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + app.infoLog.Printf("%s - %s %s %s", r.RemoteAddr, r.Proto, r.Method, r.URL.RequestURI()) + + next.ServeHTTP(w, r) + }) +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go index da5ea9f..9d79b21 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -12,5 +12,5 @@ func (app *application) routes() http.Handler { mux.HandleFunc("/snippet/view", app.snippetView) mux.HandleFunc("/snippet/create", app.snippetCreate) - return secureHeaders(mux) + return app.logRequest(secureHeaders(mux)) }