2023-06-17 04:08:50 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httputil"
|
2023-06-17 22:41:07 +00:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2023-06-17 04:08:50 +00:00
|
|
|
)
|
|
|
|
|
2023-06-17 22:41:07 +00:00
|
|
|
func LogMiddleware(lg *logrus.Logger) func(http.Handler) http.Handler {
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
lg.Debugf("%s - %s - %s", r.Method, r.URL, r.Host)
|
2023-06-17 04:08:50 +00:00
|
|
|
|
2023-06-17 22:41:07 +00:00
|
|
|
hasBody := false
|
|
|
|
if r.Method == "PUT" {
|
|
|
|
hasBody = true
|
|
|
|
}
|
2023-06-17 04:08:50 +00:00
|
|
|
|
2023-06-17 22:41:07 +00:00
|
|
|
requestDump, err := httputil.DumpRequest(r, hasBody)
|
|
|
|
if err != nil {
|
|
|
|
lg.Debugln(err)
|
|
|
|
}
|
|
|
|
lg.Debugln("RequestDump: ", string(requestDump))
|
2023-06-17 04:08:50 +00:00
|
|
|
|
2023-06-17 22:41:07 +00:00
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|
2023-06-17 04:08:50 +00:00
|
|
|
}
|