| } | } | ||||
| func getClientIP(r *http.Request) string { | func getClientIP(r *http.Request) string { | ||||
| //a := r.RemoteAddr // always be 127.0.0.1:300456 port number may vary | |||||
| a := r.Header.Get("X-Forwarded-For") | |||||
| a := r.RemoteAddr // always be 127.0.0.1:300456 port number may vary | |||||
| s := strings.Split(a, ":") | s := strings.Split(a, ":") | ||||
| if s[0] == "127.0.0.1" { //loopback address | |||||
| ip := r.Header.Get("X-Forwarded-For") | |||||
| return ip | |||||
| } | |||||
| return s[0] | return s[0] | ||||
| } | } | ||||