feat(init): First commit
This commit is contained in:
commit
f92368748a
22 changed files with 1298 additions and 0 deletions
29
pkg/utils/domain.go
Normal file
29
pkg/utils/domain.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue