fix: use net.JoinHostPort instead of fmt.Sprintf

The net.JoinHostPort function handles both ipv4 and ipv6 cases
pull/10/head
ffmiyo 2020-12-21 12:46:01 +08:00 committed by Karan Sharma
parent d406d54170
commit 539e89e1fe
1 changed files with 1 additions and 10 deletions

View File

@ -68,16 +68,7 @@ func getDefaultServers() ([]Nameserver, int, error) {
} }
servers := make([]Nameserver, 0, len(cfg.Servers)) servers := make([]Nameserver, 0, len(cfg.Servers))
for _, s := range cfg.Servers { for _, s := range cfg.Servers {
var ( addr := net.JoinHostPort(s, cfg.Port)
ip = net.ParseIP(s)
addr string
)
// handle IPv6
if ip != nil && ip.To4() != nil {
addr = fmt.Sprintf("%s:%s", s, cfg.Port)
} else {
addr = fmt.Sprintf("[%s]:%s", s, cfg.Port)
}
ns := Nameserver{ ns := Nameserver{
Type: UDPResolver, Type: UDPResolver,
Address: addr, Address: addr,