Browse Source

handling 127.0.0.1

tags/v0.5
patrick 5 years ago
parent
commit
4c5737ee04
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      ip2long.go

+ 5
- 2
ip2long.go View File

} }


func getClientIP(r *http.Request) string { func getClientIP(r *http.Request) string {
//a := r.RemoteAddr // always be 127.0.0.1:300456 port number may vary
a := r.Header.Get("X-Forwarded-For")
a := r.RemoteAddr // always be 127.0.0.1:300456 port number may vary
s := strings.Split(a, ":") s := strings.Split(a, ":")
if s[0] == "127.0.0.1" { //loopback address
ip := r.Header.Get("X-Forwarded-For")
return ip
}
return s[0] return s[0]
} }



Loading…
Cancel
Save