feat(init): First commit

This commit is contained in:
Thomas Maurice 2024-02-11 19:59:34 +01:00
commit f92368748a
Signed by: thomas
GPG key ID: 1D577F50583032A6
22 changed files with 1298 additions and 0 deletions

29
pkg/utils/domain.go Normal file
View file

@ -0,0 +1,29 @@
package utils
import (
"fmt"
"strings"
)
func GetZone(domain string) (string, error) {
splt := strings.Split(domain, ".")
if len(splt) == 1 {
return "", fmt.Errorf("invalid domain %s", domain)
}
if len(splt) == 2 {
return domain, nil
}
return splt[len(splt)-2] + "." + splt[len(splt)-1], nil
}
func GetSubdomain(domain string) (string, error) {
top, err := GetZone(domain)
if err != nil {
return "", err
}
sub := strings.TrimSuffix(domain, top)
return strings.TrimSuffix(sub, "."), nil
}