go-zero/rest/httpx/util.go
2021-10-20 17:50:01 +08:00

16 lines
276 B
Go

package httpx
import "net/http"
const xForwardedFor = "X-Forwarded-For"
// GetRemoteAddr returns the peer address, supports X-Forward-For.
func GetRemoteAddr(r *http.Request) string {
v := r.Header.Get(xForwardedFor)
if len(v) > 0 {
return v
}
return r.RemoteAddr
}