mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
15 lines
269 B
Go
15 lines
269 B
Go
package httpx
|
|
|
|
import "net/http"
|
|
|
|
const xForwardFor = "X-Forward-For"
|
|
|
|
// GetRemoteAddr returns the peer address, supports X-Forward-For.
|
|
func GetRemoteAddr(r *http.Request) string {
|
|
v := r.Header.Get(xForwardFor)
|
|
if len(v) > 0 {
|
|
return v
|
|
}
|
|
return r.RemoteAddr
|
|
}
|