authorizer/server/utils/request_info.go
2022-01-17 11:32:13 +05:30

22 lines
447 B
Go

package utils
import "net/http"
// GetIP helps in getting the IP address from the request
func GetIP(r *http.Request) string {
IPAddress := r.Header.Get("X-Real-Ip")
if IPAddress == "" {
IPAddress = r.Header.Get("X-Forwarded-For")
}
if IPAddress == "" {
IPAddress = r.RemoteAddr
}
return IPAddress
}
// GetUserAgent helps in getting the user agent from the request
func GetUserAgent(r *http.Request) string {
return r.UserAgent()
}