pull/627/head
kompotkot 2022-06-06 14:33:50 +00:00
rodzic 6d57281f6d
commit 18acd37a57
1 zmienionych plików z 10 dodań i 4 usunięć

Wyświetl plik

@ -184,10 +184,16 @@ func logMiddleware(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
http.Error(w, fmt.Sprintf("Unable to parse client IP: %s", r.RemoteAddr), http.StatusBadRequest)
return
var ip string
realIp := r.Header["X-Real-Ip"]
if len(realIp) == 0 {
ip, _, err = net.SplitHostPort(r.RemoteAddr)
if err != nil {
http.Error(w, fmt.Sprintf("Unable to parse client IP: %s", r.RemoteAddr), http.StatusBadRequest)
return
}
} else {
ip = realIp[0]
}
logStr := fmt.Sprintf("%s %s %s", ip, r.Method, r.URL.Path)