diff options
| -rw-r--r-- | cmd/resolver/main.go | 55 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 4 |
3 files changed, 7 insertions, 54 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go index e5e7548..2fdfe3b 100644 --- a/cmd/resolver/main.go +++ b/cmd/resolver/main.go @@ -7,8 +7,6 @@ import ( "fmt" "log" "math/rand" - "net" - "net/url" "strings" "time" @@ -49,54 +47,6 @@ func initSystemResolver() (rc *libnet.ResolvConf, cl dns.Client) { return } -func createDNSClient(opts *options) (cl dns.Client) { - var ( - ns = opts.nameserver - iphost string - port string - ) - - nsurl, err := url.Parse(ns) - if err != nil { - log.Fatalf("! invalid name server: %q\n", ns) - } - - ipport := strings.Split(nsurl.Host, ":") - switch len(ipport) { - case 1: - iphost = ipport[0] - case 2: - iphost = ipport[0] - port = ipport[1] - default: - log.Fatalf("! invalid name server: %q\n", ns) - } - - switch nsurl.Scheme { - case "udp": - cl, err = dns.NewUDPClient(nsurl.Host) - case "tcp": - cl, err = dns.NewTCPClient(nsurl.Host) - case "https": - ip := net.ParseIP(iphost) - if ip != nil { - if len(port) == 0 { - port = "853" - } - cl, err = dns.NewDoTClient(iphost+":"+port, opts.insecure) - } else { - cl, err = dns.NewDoHClient(ns, opts.insecure) - } - default: - log.Fatalf("! createDNSClient: unknown scheme %q", nsurl.Scheme) - } - if err != nil { - log.Fatal("! createDNSClient: " + err.Error()) - } - - return cl -} - func populateQueries(cr *libnet.ResolvConf, qname string) (queries []string) { ndots := 0 @@ -236,7 +186,10 @@ func main() { if len(opts.nameserver) == 0 { cl = systemResolver } else { - cl = createDNSClient(opts) + cl, err = dns.NewClient(opts.nameserver, opts.insecure) + if err != nil { + log.Fatal(err) + } } queries := populateQueries(rc, opts.qname) @@ -5,6 +5,6 @@ module github.com/shuLhan/rescached-go/v4 go 1.16 -require github.com/shuLhan/share v0.36.1-0.20220405193722-429a9d9205ba +require github.com/shuLhan/share v0.36.1-0.20220411183137-8422dd7cdee8 //replace github.com/shuLhan/share => ../share @@ -1,5 +1,5 @@ -github.com/shuLhan/share v0.36.1-0.20220405193722-429a9d9205ba h1:zc9/aydsu8QdNfdf/ESk7EgsP7zvzlOrVruQdX0uH4o= -github.com/shuLhan/share v0.36.1-0.20220405193722-429a9d9205ba/go.mod h1:laKGR1DNboj8+INRIC9VFYRiVEu/IIjrLurUmTHXkw0= +github.com/shuLhan/share v0.36.1-0.20220411183137-8422dd7cdee8 h1:37XdJj5KXgwLSy0TmnWjo29Ez8ze50T7lsh0wcs7ROA= +github.com/shuLhan/share v0.36.1-0.20220411183137-8422dd7cdee8/go.mod h1:laKGR1DNboj8+INRIC9VFYRiVEu/IIjrLurUmTHXkw0= golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= |
