mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-07 06:00:06 +00:00
Add DDNS Profiles, use publicsuffixlist domain parser (#350)
* Add DDNS Profiles, use publicsuffixlist domain parser * Add Tencent Cloud DNS Provider * Restore validate DDNS provider function * chore: fmt & upgrade dependencies
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package ddns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
@@ -33,29 +33,8 @@ func SetStringHeadersToRequest(req *http.Request, headers []string) {
|
||||
}
|
||||
|
||||
// SplitDomain 分割域名为前缀和一级域名
|
||||
func SplitDomain(domain string) (prefix string, topLevelDomain string) {
|
||||
// 带有二级TLD的一些常见例子,需要特别处理
|
||||
secondLevelTLDs := map[string]bool{
|
||||
".co.uk": true, ".com.cn": true, ".gov.cn": true, ".net.cn": true, ".org.cn": true,
|
||||
}
|
||||
|
||||
// 分割域名为"."的各部分
|
||||
parts := strings.Split(domain, ".")
|
||||
|
||||
// 处理特殊情况,例如 ".co.uk"
|
||||
for i := len(parts) - 2; i > 0; i-- {
|
||||
potentialTLD := fmt.Sprintf(".%s.%s", parts[i], parts[i+1])
|
||||
if secondLevelTLDs[potentialTLD] {
|
||||
if i > 1 {
|
||||
return strings.Join(parts[:i-1], "."), strings.Join(parts[i-1:], ".")
|
||||
}
|
||||
return "", domain // 当域名仅为二级TLD时,无前缀
|
||||
}
|
||||
}
|
||||
|
||||
// 常规处理,查找最后一个"."前的所有内容作为前缀
|
||||
if len(parts) > 2 {
|
||||
return strings.Join(parts[:len(parts)-2], "."), strings.Join(parts[len(parts)-2:], ".")
|
||||
}
|
||||
return "", domain // 当域名不包含子域名时,无前缀
|
||||
func SplitDomain(domain string) (prefix string, realDomain string) {
|
||||
realDomain, _ = publicsuffix.EffectiveTLDPlusOne(domain)
|
||||
prefix = domain[:len(domain)-len(realDomain)-1]
|
||||
return prefix, realDomain
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user