fix: use sld match instead of string suffix match

This commit is contained in:
kenshinx 2017-05-18 18:22:15 +08:00
parent 5f42911d12
commit 3be40025e0
1 changed files with 11 additions and 2 deletions

View File

@ -104,16 +104,25 @@ type RedisHosts struct {
func (r *RedisHosts) Get(domain string) ([]string, bool) {
r.mu.RLock()
defer r.mu.RUnlock()
domain = strings.ToLower(domain)
ip, ok := r.hosts[domain]
if ok {
return strings.Split(ip, ","), true
}
sld, err := publicsuffix.EffectiveTLDPlusOne(domain)
if err != nil {
return nil, false
}
for host, ip := range r.hosts {
if strings.HasPrefix(host, "*.") {
upperLevelDomain := strings.Split(host, "*.")[1]
if strings.HasSuffix(domain, upperLevelDomain) {
old, err := publicsuffix.EffectiveTLDPlusOne(host)
if err != nil {
continue
}
if sld == old {
return strings.Split(ip, ","), true
}
}