提升通过域名查找服务的性能,轻松支持海量域名

This commit is contained in:
GoEdgeLab
2021-11-15 16:56:31 +08:00
parent 842684ca29
commit 2c114a6b1d
6 changed files with 310 additions and 26 deletions
+20
View File
@@ -27,6 +27,10 @@ func MatchDomain(pattern string, domain string) (isMatched bool) {
return
}
if pattern == domain {
return true
}
if pattern == "*" {
return true
}
@@ -61,3 +65,19 @@ func MatchDomain(pattern string, domain string) (isMatched bool) {
}
return isMatched
}
// IsFuzzyDomain 判断是否为特殊域名
func IsFuzzyDomain(domain string) bool {
if len(domain) == 0 {
return true
}
if domain[0] == '.' || domain[0] == '~' {
return true
}
for _, c := range domain {
if c == '*' {
return true
}
}
return false
}
+11
View File
@@ -81,3 +81,14 @@ func TestMatchDomain(t *testing.T) {
a.IsTrue(ok)
}
}
func TestIsSpecialDomain(t *testing.T) {
var a = assert.NewAssertion(t)
a.IsTrue(IsFuzzyDomain(""))
a.IsTrue(IsFuzzyDomain(".hello.com"))
a.IsTrue(IsFuzzyDomain("*.hello.com"))
a.IsTrue(IsFuzzyDomain("hello.*.com"))
a.IsTrue(IsFuzzyDomain("~^hello\\.com"))
a.IsFalse(IsFuzzyDomain("hello.com"))
}