You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/rest/httpx/util.go

15 lines
275 B
Go

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