diff --git a/logs.go b/logs.go index debe824..ef3fe51 100644 --- a/logs.go +++ b/logs.go @@ -58,12 +58,6 @@ func setLog(cfg *cfg.Config) { } func getIP(r *http.Request) (string, error) { - //Get IP from the X-REAL-IP header - ip := r.Header.Get("X-REAL-IP") - netIP := net.ParseIP(ip) - if netIP != nil { - return ip, nil - } //Get IP from X-FORWARDED-FOR header ips := r.Header.Get("X-FORWARDED-FOR") splitIps := strings.Split(ips, ",") @@ -78,6 +72,12 @@ func getIP(r *http.Request) (string, error) { if err != nil { return "", err } + netIP := net.ParseIP(ip) + if netIP != nil { + return ip, nil + } + //Get IP from the X-REAL-IP header + ip = r.Header.Get("X-REAL-IP") netIP = net.ParseIP(ip) if netIP != nil { return ip, nil