Something went wrong. Try again.
A tool for managing custom bluesky feeds
Something went wrong. Try again.
968 B · 39 lines
Go
at main
12345678910111213141516171819202122232425262728293031323334353637383940package server
import ( "log/slog" "net/http" "time")
// responseWriter wraps http.ResponseWriter to capture the status code.type responseWriter struct { http.ResponseWriter statusCode int}
// WriteHeader captures the status code.func (rw *responseWriter) WriteHeader(code int) { rw.statusCode = code rw.ResponseWriter.WriteHeader(code)}
// loggingMiddleware wraps an http.Handler to log request details.func loggingMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { wrapped := &responseWriter{ResponseWriter: w} next.ServeHTTP(wrapped, r) start := time.Now() duration := time.Since(start) if wrapped.statusCode == 0 { wrapped.statusCode = 200 } slog.Info( "", slog.String("verb", r.Method), slog.String("path", r.URL.Path), slog.Uint64("code", uint64(wrapped.statusCode)), slog.Float64("duration", float64(duration.Nanoseconds())/1_000_000), ) })}