adding a RealIP func

This commit is contained in:
Vincent Batts 2013-06-18 15:09:12 -04:00
parent e462a16204
commit de330d561a

View file

@ -13,7 +13,7 @@ func LogRequest(r *http.Request, statusCode int) {
var user_agent string
user_agent = ""
addr = r.RemoteAddr
addr = RealIP(r)
for k, v := range r.Header {
if k == "User-Agent" {
@ -33,3 +33,20 @@ func LogRequest(r *http.Request, statusCode int) {
statusCode,
r.ContentLength)
}
func RealIP(r *http.Request) (ip string) {
ip = r.RemoteAddr
port_pos := strings.LastIndex(ip, ":")
if port_pos != -1 {
ip = ip[0:port_pos]
}
for k, v := range r.Header {
if k == "X-Forwarded-For" {
ip = strings.Join(v, " ")
}
}
return ip
}