mirror of https://github.com/EasyDarwin/EasyDarwin
23 lines
403 B
Go
23 lines
403 B
Go
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func GetRequestHref(r *http.Request) string {
|
|
scheme := "http://"
|
|
if r.TLS != nil {
|
|
scheme = "https://"
|
|
}
|
|
return strings.Join([]string{scheme, r.Host, r.RequestURI}, "")
|
|
}
|
|
|
|
func GetRequestHostname(r *http.Request) (hostname string) {
|
|
if _url, err := url.Parse(GetRequestHref(r)); err == nil {
|
|
hostname = _url.Hostname()
|
|
}
|
|
return
|
|
}
|