chore: move X-FORWARDED-FOR at first for ip request log
This commit is contained in:
parent
618f5d884c
commit
6f0b9b70a5
12
logs.go
12
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
|
||||
|
Loading…
Reference in New Issue
Block a user