feat: Multiple resolvers continued
This commit is contained in:
parent
b46b64c1ae
commit
53e7f2e59c
11 changed files with 253 additions and 214 deletions
|
@ -1,11 +1,6 @@
|
|||
package resolvers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
|
@ -23,26 +18,3 @@ func prepareMessages(questions []dns.Question) []dns.Msg {
|
|||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func getDefaultServers() ([]string, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
// TODO: Add a method for reading system default nameserver in windows.
|
||||
return nil, errors.New(`unable to read default nameservers in this machine`)
|
||||
}
|
||||
// if no nameserver is provided, take it from `resolv.conf`
|
||||
cfg, err := dns.ClientConfigFromFile(DefaultResolvConfPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
servers := make([]string, 0, len(cfg.Servers))
|
||||
for _, s := range cfg.Servers {
|
||||
ip := net.ParseIP(s)
|
||||
// handle IPv6
|
||||
if ip != nil && ip.To4() != nil {
|
||||
servers = append(servers, fmt.Sprintf("%s:%s", s, cfg.Port))
|
||||
} else {
|
||||
servers = append(servers, fmt.Sprintf("[%s]:%s", s, cfg.Port))
|
||||
}
|
||||
}
|
||||
return servers, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue