mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
15 lines
254 B
Go
15 lines
254 B
Go
package httpx
|
|
|
|
import "net/http"
|
|
|
|
const xForwardFor = "X-Forward-For"
|
|
|
|
// 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
|
|
}
|