Initial commit.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user