Skip to content

Commit

Permalink
Add ToLower to all domain fields kenshinx#24
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshinx committed Feb 15, 2016
1 parent fde6624 commit 4275900
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type RedisHosts struct {
}

func (r *RedisHosts) Get(domain string) ([]string, bool) {
domain = strings.ToLower(domain)
ip, ok := r.hosts[domain]
if ok {
return strings.Split(ip, ","), true
Expand All @@ -112,7 +113,7 @@ func (r *RedisHosts) Get(domain string) ([]string, bool) {
}

func (r *RedisHosts) Set(domain, ip string) (bool, error) {
return r.redis.Hset(r.key, domain, []byte(ip))
return r.redis.Hset(r.key, strings.ToLower(domain), []byte(ip))
}

func (r *RedisHosts) Refresh() {
Expand All @@ -130,6 +131,7 @@ type FileHosts struct {
}

func (f *FileHosts) Get(domain string) ([]string, bool) {
domain = strings.ToLower(domain)
ip, ok := f.hosts[domain]
if !ok {
return nil, false
Expand Down Expand Up @@ -172,7 +174,7 @@ func (f *FileHosts) Refresh() {
continue
}

f.hosts[domain] = ip
f.hosts[strings.ToLower(domain)] = ip
}
logger.Debug("update hosts records from %s", f.file)
}
Expand Down

0 comments on commit 4275900

Please sign in to comment.