Remove utils package as it's only used in the dns package
parent
e151e3dbfd
commit
4e16bab92e
@ -1,25 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SplitHost returns hostname into domain and subdomain strings.
|
|
||||||
// For example:
|
|
||||||
// "some.subdomain.example.com" → ("some.subdomain", "example.com", nil)
|
|
||||||
// "example.com" → ("", "example.com", nil)
|
|
||||||
func SplitHost(host string) (subdomain string, domain string, err error) {
|
|
||||||
subdomains := strings.Split(host, ".")
|
|
||||||
|
|
||||||
if len(subdomains) >= 3 {
|
|
||||||
domain = strings.Join(subdomains[len(subdomains)-2:], ".")
|
|
||||||
subdomain = strings.Join(subdomains[:len(subdomains)-2], ".")
|
|
||||||
} else if len(subdomains) == 2 {
|
|
||||||
domain = strings.Join(subdomains, ".")
|
|
||||||
} else {
|
|
||||||
err = errors.New("invalid domain")
|
|
||||||
}
|
|
||||||
return subdomain, domain, err
|
|
||||||
}
|
|
Loading…
Reference in New Issue