func FromRequest(r *http.Request) string {
	// Fetch header value
	xRealIP := r.Header.Get("X-Real-Ip")
	xForwardedFor := r.Header.Get("X-Forwarded-For")

	// If both empty, return IP from remote address
	if xRealIP == "" && xForwardedFor == "" {
		var remoteIP string

		// If there are colon in remote address, remove the port number
		// otherwise, return remote address as is
		if strings.ContainsRune(r.RemoteAddr, ':') {
			remoteIP, _, _ = net.SplitHostPort(r.RemoteAddr)
		} else {
			remoteIP = r.RemoteAddr
		}

		return remoteIP
	}

	// Check list of IP in X-Forwarded-For and return the first global address
	for _, address := range strings.Split(xForwardedFor, ",") {
		address = strings.TrimSpace(address)
		isPrivate, err := isPrivateAddress(address)
		if !isPrivate && err == nil {
			return address
		}
	}

	// If nothing succeed, return X-Real-IP
	return xRealIP
}
func FromRequest(r *http.Request) string {
	
	xRealIP := r.Header.Get("X-Real-Ip")
	xForwardedFor := r.Header.Get("X-Forwarded-For")

	
	if xRealIP == "" && xForwardedFor == "" {
		var remoteIP string

		
		
		if strings.ContainsRune(r.RemoteAddr, ':') {
			remoteIP, _, _ = net.SplitHostPort(r.RemoteAddr)
		} else {
			remoteIP = r.RemoteAddr
		}

		return remoteIP
	}

	
	for _, address := range strings.Split(xForwardedFor, ",") {
		address = strings.TrimSpace(address)
		isPrivate, err := isPrivateAddress(address)
		if !isPrivate && err == nil {
			return address
		}
	}

	
	return xRealIP
}
func FromRequest ( r * http . Request ) string { // Fetch header value xRealIP := r . Header . Get ( " " ) xForwardedFor := r . Header . Get ( " " ) // If both empty, return IP from remote address if xRealIP == " " && xForwardedFor == " " { var remoteIP string // If there are colon in remote address, remove the port number // otherwise, return remote address as is if strings . ContainsRune ( r . RemoteAddr , ':' ) { remoteIP , _ , _ = net . SplitHostPort ( r . RemoteAddr ) } else { remoteIP = r . RemoteAddr } return remoteIP } // Check list of IP in X-Forwarded-For and return the first global address for _ , address := range strings . Split ( xForwardedFor , " " ) { address = strings . TrimSpace ( address ) isPrivate , err := isPrivateAddress ( address ) if ! isPrivate && err == nil { return address } } // If nothing succeed, return X-Real-IP return xRealIP }
// FromRequest return client's real public IP address from http request headers.
FromRequest return client s real public IP address from http request headers .