chore(go): simplify sourceIP logic
This commit is contained in:
parent
796b0b3839
commit
265c998df0
1 changed files with 1 additions and 4 deletions
5
main.go
5
main.go
|
@ -80,11 +80,8 @@ func getIPCountry(ip string) string {
|
|||
|
||||
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
sourceIP := func() string {
|
||||
if ip := r.Header.Get("CF-Connecting-IP"); ip != "" {
|
||||
return ip
|
||||
}
|
||||
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
|
||||
return ip
|
||||
return strings.Split(ip, ",")[0]
|
||||
}
|
||||
return strings.Split(r.RemoteAddr, ":")[0]
|
||||
}()
|
||||
|
|
Loading…
Reference in a new issue