mirror of
https://github.com/1f349/violet.git
synced 2024-11-21 19:01:39 +00:00
Replace bodged GetTopFqdn with eTLD+1
This commit is contained in:
parent
37b0617e78
commit
fc2f3d5b7b
@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"golang.org/x/net/publicsuffix"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -65,17 +66,8 @@ func GetParentDomain(domain string) (string, bool) {
|
|||||||
//
|
//
|
||||||
// hello.world.example.com => example.com
|
// hello.world.example.com => example.com
|
||||||
func GetTopFqdn(domain string) (string, bool) {
|
func GetTopFqdn(domain string) (string, bool) {
|
||||||
n := strings.LastIndexByte(domain, '.')
|
out, err := publicsuffix.EffectiveTLDPlusOne(domain)
|
||||||
// if a valid index isn't found then return false
|
return out, err == nil
|
||||||
if n == -1 {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
// if a valid index isn't found then this is the fqdn
|
|
||||||
n2 := strings.LastIndexByte(domain[:n], '.')
|
|
||||||
if n2 == -1 {
|
|
||||||
return domain, true
|
|
||||||
}
|
|
||||||
return domain[n2+1:], true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitHostPath extracts the host/path from the input
|
// SplitHostPath extracts the host/path from the input
|
||||||
|
Loading…
Reference in New Issue
Block a user