-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpsuffix.go
41 lines (30 loc) · 949 Bytes
/
psuffix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"strings"
"golang.org/x/net/publicsuffix"
)
// parentDomains returns parent and suffix domains
// for example:
// parentDomains("www.google.com") -> "google.com", ""
// parentDomains("www.google.co.uk") -> "google.co.uk", "co.uk"
func parentDomains(domain string) (string, string) {
parent, err := publicsuffix.EffectiveTLDPlusOne(domain)
if err != nil {
// logger.Debug.Printf("parentDomains Error: %s -> %s\n", domain, err)
parent = domain
}
// logger.Debug.Printf("parentDomains: %s -> %s\n", domain, parent)
if _, _, ok := strings.Cut(parent, "."); !ok {
return "", ""
}
suffix, icann := publicsuffix.PublicSuffix(domain)
if icann {
return parent, ""
}
// logger.Debug.Printf("suffixDomains: %s -> %s\n", domain, suffix)
if _, _, ok := strings.Cut(suffix, "."); !ok {
return parent, ""
}
// logger.Debug.Printf("suffix/parent Domains: %s, %s\n", parent, suffix)
return parent, suffix
}