From 4131a32a2847eedbf1a7f3ff4ee0e716bf41b9cd Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Sun, 29 Mar 2026 11:35:08 +0300 Subject: ok --- server/main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server/main.go b/server/main.go index 011f286..fdeca05 100644 --- a/server/main.go +++ b/server/main.go @@ -12,6 +12,20 @@ import ( //go:embed static/* var staticFS embed.FS +func loggingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + slog.Info("request", "method", r.Method, "path", r.URL.Path) + next.ServeHTTP(w, r) + }) +} + +func cacheMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "public, max-age=3600") + next.ServeHTTP(w, r) + }) +} + func main() { addr := flag.String("addr", ":8080", "listen address") flag.Parse() @@ -27,8 +41,7 @@ func main() { } fileServer := http.FileServer(http.FS(subFS)) - w.Header().Set("Cache-Control", "public, max-age=3600") - http.Handle("/", loggingMiddleware(fileServer)) + http.Handle("/", loggingMiddleware(cacheMiddleware(fileServer))) slog.Info("starting server", "addr", *addr) if err := http.ListenAndServe(*addr, nil); err != nil { -- cgit v1.3