internal/home: Add a status page on home

This commit is contained in:
Tom Wiesing 2022-10-06 15:32:02 +02:00
parent 7cda92b342
commit 3d4db1744b
No known key found for this signature in database
9 changed files with 301 additions and 118 deletions

View file

@ -42,18 +42,26 @@ func (cfg Config) DefaultSSLHost() string {
return cfg.IfHttps(cfg.DefaultHost())
}
// SlugFromHost returns the slug belonging to the appropriate host.
func (cfg Config) SlugFromHost(host string) (slug string) {
// SlugFromHost returns the slug belonging to the appropriate host.'
//
// When host is a top-level domain, returns "", true.
// When no slug is found, returns "", false.
func (cfg Config) SlugFromHost(host string) (slug string, ok bool) {
// extract an ':port' that happens to be in the host.
domain, _, _ := strings.Cut(host, ":")
domainL := strings.ToLower(domain)
// check all the possible domain endings
for _, suffix := range append([]string{cfg.DefaultDomain}, cfg.SelfExtraDomains...) {
if strings.HasSuffix(domain, "."+suffix) {
return domain[:len(domain)-len(suffix)-1]
suffixL := strings.ToLower(suffix)
if domainL == suffixL {
return "", true
}
if strings.HasSuffix(domainL, "."+suffixL) {
return domain[:len(domain)-len(suffix)-1], true
}
}
// no domain found!
return ""
return "", ok
}