Files
go-zero/rest/httpx/util.go
2021-02-26 16:17:30 +08:00

15 lines
271 B
Go

package httpx
import "net/http"
const xForwardFor = "X-Forwarded-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
}