You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
630 B
25 lines
630 B
package utils |
|
|
|
import ( |
|
"net/http" |
|
"strings" |
|
) |
|
|
|
//GenerateClientIDFromRequest generates a client id from the provided request |
|
func GenerateClientIDFromRequest(req *http.Request) string { |
|
var clientID string |
|
|
|
xForwardedFor := req.Header.Get("X-FORWARDED-FOR") |
|
if xForwardedFor != "" { |
|
clientID = xForwardedFor |
|
} else { |
|
ipAddressString := req.RemoteAddr |
|
ipAddressComponents := strings.Split(ipAddressString, ":") |
|
ipAddressComponents[len(ipAddressComponents)-1] = "" |
|
clientID = strings.Join(ipAddressComponents, ":") |
|
} |
|
|
|
// fmt.Println("IP address determined to be", ipAddress) |
|
|
|
return clientID + req.UserAgent() |
|
}
|
|
|