Last active
June 4, 2021 02:52
-
-
Save oofnivek/fd2412ee9b664597575a38d6c8806de6 to your computer and use it in GitHub Desktop.
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/http" | |
) | |
func GetCountry(r *http.Request) string { | |
return r.Header.Get("CF-IPCountry") | |
} | |
func GetUserAgent(r *http.Request) string { | |
return r.Header.Get("User-Agent") | |
} | |
func GetIpAddress(r *http.Request) string { | |
forwarded := r.Header.Get("X-Forwarded-For") | |
if len(forwarded)>0 { | |
return forwarded | |
} | |
return r.RemoteAddr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment