func GetIPAddress(r *http.Request) string {
	hdr := r.Header
	hdrRealIp := hdr.Get("X-Real-Ip")
	hdrForwardedFor := hdr.Get("X-Forwarded-For")
	if hdrRealIp == "" && hdrForwardedFor == "" {
		hostWithoutPort, _, _ := net.SplitHostPort(r.RemoteAddr)
		return hostWithoutPort
	}
	if hdrForwardedFor != "" {
		// X-Forwarded-For is potentially a list of addresses separated with ","
		parts := strings.Split(hdrForwardedFor, ",")
		for i, p := range parts {
			parts[i] = strings.TrimSpace(p)
		}
		// TODO: should return first non-local address
		return parts[0]
	}
	return hdrRealIp
}
// GetIPAddress returns a user's IP address, even if your Go app is sitting behind
// a reverse proxy.
//From https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/lomWKs0kOfE
GetIPAddress returns a user's IP address, even if your Go app is sitting behind
a reverse proxy.
// GetIPAddress returns a user ' s IP address even if your Go app is sitting behind // a reverse proxy . // From https : // groups . google . com / forum / ?fromgroups#!topic / golang - nuts / lomWKs0kOfE
func GetIPAddress(r *http.Request) string {
	hdr := r.Header
	hdrRealIp := hdr.Get("X-Real-Ip")
	hdrForwardedFor := hdr.Get("X-Forwarded-For")
	if hdrRealIp == "" && hdrForwardedFor == "" {
		hostWithoutPort, _, _ := net.SplitHostPort(r.RemoteAddr)
		return hostWithoutPort
	}
	if hdrForwardedFor != "" {
		parts := strings.Split(hdrForwardedFor, ",")
		for i, p := range parts {
			parts[i] = strings.TrimSpace(p)
		}
		return parts[0]
	}
	return hdrRealIp
}
func GetIPAddress ( r * http . Request ) string { hdr := r . Header hdrRealIp := hdr . Get ( " " ) hdrForwardedFor := hdr . Get ( " " ) if hdrRealIp == " " && hdrForwardedFor == " " { hostWithoutPort , _ , _ := net . SplitHostPort ( r . RemoteAddr ) return hostWithoutPort } if hdrForwardedFor != " " { parts := strings . Split ( hdrForwardedFor , " " ) for i , p := range parts { parts [ i ] = strings . TrimSpace ( p ) } return parts [ 0 ] } return hdrRealIp }
GetIPAddress returns a user's IP address, even if your Go app is sitting behind
a reverse proxy.
GetIPAddress returns a user ' s IP address even if your Go app is sitting behind a reverse proxy .
// X-Forwarded-For is potentially a list of addresses separated with "," // TODO: should return first non-local address