update hosts

This commit is contained in:
ginuerzh
2022-01-01 22:49:38 +08:00
parent 4bf754b83b
commit 14537d16ea
6 changed files with 62 additions and 63 deletions

View File

@ -15,7 +15,7 @@ import (
type Router struct {
Retries int
Chain *Chain
Hosts *hosts.Hosts
Hosts hosts.HostMapper
Resolver resolver.Resolver
Logger logger.Logger
}
@ -78,9 +78,11 @@ func (r *Router) resolve(ctx context.Context, addr string) (string, error) {
return "", err
}
if ip := r.Hosts.Lookup(host); ip != nil {
r.Logger.Debugf("hit hosts: %s -> %s", host, ip)
return net.JoinHostPort(ip.String(), port), nil
if r.Hosts != nil {
if ip := r.Hosts.Lookup(host); ip != nil {
r.Logger.Debugf("hit hosts: %s -> %s", host, ip)
return net.JoinHostPort(ip.String(), port), nil
}
}
if r.Resolver != nil {