chore: move X-FORWARDED-FOR at first for ip request log

This commit is contained in:
JesusPerez 2022-03-07 22:14:46 +00:00
parent 618f5d884c
commit 6f0b9b70a5

12
logs.go
View File

@ -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