feat: login wall (#42)

* feat: add login-wall app

* fix: rename vars

* fix: rename vars

* update docker file

* add validations for app state

* add host check for app

* fix: docker file
This commit is contained in:
Lakhan Samani
2021-08-04 12:18:57 +05:30
committed by GitHub
parent d1973c1f8f
commit f88363e6dc
41 changed files with 2274 additions and 120 deletions

View File

@@ -2,11 +2,24 @@ package utils
import (
"net/url"
"strings"
)
// function to get hostname
func GetHostName(auth_url string) string {
u, err := url.Parse(auth_url)
if err != nil {
return `localhost`
}
host := u.Hostname()
return host
}
// function to get domain name
func GetDomainName(auth_url string) string {
u, err := url.Parse("//" + auth_url)
u, err := url.Parse(auth_url)
if err != nil {
return `localhost`
}
@@ -14,24 +27,24 @@ func GetDomainName(auth_url string) string {
host := u.Hostname()
// code to get root domain in case of sub-domains
// hostParts := strings.Split(host, ".")
// hostPartsLen := len(hostParts)
hostParts := strings.Split(host, ".")
hostPartsLen := len(hostParts)
// if hostPartsLen == 1 {
// return host
// }
if hostPartsLen == 1 {
return host
}
// if hostPartsLen == 2 {
// if hostParts[0] == "www" {
// return hostParts[1]
// } else {
// return host
// }
// }
if hostPartsLen == 2 {
if hostParts[0] == "www" {
return hostParts[1]
} else {
return host
}
}
// if hostPartsLen > 2 {
// return strings.Join(hostParts[hostPartsLen-2:], ".")
// }
if hostPartsLen > 2 {
return strings.Join(hostParts[hostPartsLen-2:], ".")
}
return host
}