Files
authorizer/server/utils/urls.go

38 lines
566 B
Go
Raw Normal View History

package utils
import (
"net/url"
2021-07-22 05:22:53 +05:30
"strings"
2021-07-23 21:57:44 +05:30
"github.com/authorizerdev/authorizer/server/constants"
)
2021-07-22 06:24:15 +05:30
func GetDomainName() string {
u, err := url.Parse(constants.FRONTEND_URL)
if err != nil {
return `localhost`
}
2021-07-22 05:22:53 +05:30
host := u.Hostname()
hostParts := strings.Split(host, ".")
hostPartsLen := len(hostParts)
2021-07-21 21:27:12 +05:30
2021-07-22 05:22:53 +05:30
if hostPartsLen == 1 {
return host
}
if hostPartsLen == 2 {
if hostParts[0] == "www" {
return hostParts[1]
} else {
return host
}
}
if hostPartsLen > 2 {
return strings.Join(hostParts[hostPartsLen-2:], ".")
}
return host
}