Skip to content

Commit

Permalink
添加处理子域名的能力
Browse files Browse the repository at this point in the history
如果用户输入的为子域名,则将其截取成为主域名后再进行查询
  • Loading branch information
KincaidYang committed Jan 16, 2024
1 parent 46aa580 commit a3ac970
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@ func handler(w http.ResponseWriter, r *http.Request) {
// 使用 publicsuffix 库获取顶级域
tld, _ := publicsuffix.PublicSuffix(domain)

// 获取主域名
mainDomain, _ := publicsuffix.EffectiveTLDPlusOne(domain)
domain = mainDomain

// 如果结果不符合预期(例如 "com.cn"),则从右向左读取域名,将第一个点右边的部分作为 TLD
if strings.Contains(tld, ".") {
parts := strings.Split(domain, ".")
parts := strings.Split(mainDomain, ".")
tld = parts[len(parts)-1]
}

Expand Down

0 comments on commit a3ac970

Please sign in to comment.