Skip to content

Instantly share code, notes, and snippets.

@oofnivek
Last active June 4, 2021 02:52
Show Gist options
  • Save oofnivek/fd2412ee9b664597575a38d6c8806de6 to your computer and use it in GitHub Desktop.
Save oofnivek/fd2412ee9b664597575a38d6c8806de6 to your computer and use it in GitHub Desktop.
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