mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-13 12:33:14 +02:00
25 lines
501 B
Go
25 lines
501 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httputil"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func LoggingMiddleware(prefix string, next http.HandlerFunc) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
log.Tracef("[%s] %s %s", prefix, r.Method, r.URL.Path)
|
|
log.Tracef("[%s]\n%s", prefix, dump(r))
|
|
r.BasicAuth()
|
|
next.ServeHTTP(w, r)
|
|
}
|
|
}
|
|
|
|
func dump(r *http.Request) string {
|
|
x, err := httputil.DumpRequest(r, true)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return string(x)
|
|
}
|