2014-10-21 20:30:19 +00:00
|
|
|
package util
|
2014-11-13 10:55:51 +00:00
|
|
|
|
2014-10-21 20:30:19 +00:00
|
|
|
import "strings"
|
|
|
|
|
2014-11-27 20:36:21 +00:00
|
|
|
// Split a domain name a.b.c.d.e into parts e (the head) and a.b.c.d (the rest).
|
2014-10-21 20:30:19 +00:00
|
|
|
func SplitDomainHead(name string) (head string, rest string, err error) {
|
2014-11-27 20:36:21 +00:00
|
|
|
if len(name) > 0 && name[len(name)-1] == '.' {
|
|
|
|
name = name[0 : len(name)-1]
|
|
|
|
}
|
|
|
|
|
2014-11-13 10:55:51 +00:00
|
|
|
parts := strings.Split(name, ".")
|
2014-10-21 20:30:19 +00:00
|
|
|
|
2014-11-13 10:55:51 +00:00
|
|
|
head = parts[len(parts)-1]
|
2014-10-21 20:30:19 +00:00
|
|
|
|
2014-11-13 10:55:51 +00:00
|
|
|
if len(parts) >= 2 {
|
|
|
|
rest = strings.Join(parts[0:len(parts)-1], ".")
|
|
|
|
}
|
2014-10-21 20:30:19 +00:00
|
|
|
|
2014-11-13 10:55:51 +00:00
|
|
|
return
|
2014-10-21 20:30:19 +00:00
|
|
|
}
|
2014-11-11 10:35:48 +00:00
|
|
|
|
|
|
|
// © 2014 Hugo Landau <hlandau@devever.net> GPLv3 or later
|