Created
September 9, 2014 07:07
-
-
Save orcaman/9b8dd3f84550d7faac38 to your computer and use it in GitHub Desktop.
Util function to get "Real" IP address in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"net/http" | |
) | |
func getIP(r *http.Request) string { | |
if ipProxy := r.Header.Get("X-FORWARDED-FOR"); len(ipProxy) > 0 { | |
return ipProxy | |
} | |
ip, _, _ := net.SplitHostPort(r.RemoteAddr) | |
return ip | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment