25 lines
463 B
Go
25 lines
463 B
Go
package httpserver
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func (h *httpServer) requestLoggingMiddleware(fn http.HandlerFunc) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
startTime := time.Now()
|
|
|
|
fn(w, r)
|
|
|
|
h.logger.Info(
|
|
"HTTP request.",
|
|
"remote_addr", r.RemoteAddr,
|
|
"user_agent", r.UserAgent(),
|
|
"host", r.Host,
|
|
"path", fmt.Sprintf("%s %s", r.Method, r.RequestURI),
|
|
"duration", time.Since(startTime),
|
|
)
|
|
}
|
|
}
|