mirror of https://github.com/mpolden/echoip
Cleanup
This commit is contained in:
parent
ed29f49139
commit
7ffaf5e9ac
15
api/api.go
15
api/api.go
|
@ -78,20 +78,17 @@ func (a *API) EnablePortTesting() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ipFromRequest(r *http.Request) (net.IP, error) {
|
func ipFromRequest(r *http.Request) (net.IP, error) {
|
||||||
var host string
|
remoteIP := r.Header.Get("X-Real-IP")
|
||||||
realIP := r.Header.Get("X-Real-IP")
|
if remoteIP == "" {
|
||||||
var err error
|
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
if realIP != "" {
|
|
||||||
host = realIP
|
|
||||||
} else {
|
|
||||||
host, _, err = net.SplitHostPort(r.RemoteAddr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
remoteIP = host
|
||||||
}
|
}
|
||||||
ip := net.ParseIP(host)
|
ip := net.ParseIP(remoteIP)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
return nil, fmt.Errorf("could not parse IP: %s", host)
|
return nil, fmt.Errorf("could not parse IP: %s", remoteIP)
|
||||||
}
|
}
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue