diff options
author | Jonathan Turner <jt@jtnet.co.uk> | 2017-11-30 10:54:58 -0800 |
---|---|---|
committer | Jonathan Turner <jt@jtnet.co.uk> | 2017-11-30 10:54:58 -0800 |
commit | 4ea2527295b59bc173164ce14bdd23e374c2e9d9 (patch) | |
tree | 9f8d37c715ce887fb9e062453f5d2d46de1208af | |
parent | 283434e0bd37593b69ab05f3f8adabbe2264d2c6 (diff) |
make backwards compatible for go <= 1.8
-rw-r--r-- | srv.go | 31 |
1 files changed, 1 insertions, 30 deletions
@@ -1,11 +1,8 @@ package dnsutils import ( - "context" - "fmt" "math/rand" "net" - "os" "sort" ) @@ -21,19 +18,8 @@ import ( // // Do something such as dial this SRV. If fails move on the the next or break if it succeeds. // i += 1 // } -// -// To override the operating system's name server set the DNSUTILS_OVERRIDE_NS environment variable. -// The override should also include the port. For example 127.0.0.1:53 func OrderedSRV(service, proto, name string) (int, map[int]*net.SRV, error) { - var addrs []*net.SRV - var err error - ns := os.Getenv("DNSUTILS_OVERRIDE_NS") - if ns != "" { - res := net.Resolver{Dial: overrideNS} - _, addrs, err = res.LookupSRV(context.Background(), service, proto, name) - } else { - _, addrs, err = net.LookupSRV(service, proto, name) - } + _, addrs, err := net.LookupSRV(service, proto, name) if err != nil { return 0, make(map[int]*net.SRV), err } @@ -41,21 +27,6 @@ func OrderedSRV(service, proto, name string) (int, map[int]*net.SRV, error) { return index, osrv, nil } -func overrideNS(ctx context.Context, network, address string) (conn net.Conn, err error) { - // Ignore the address provided and override with an environment variable if it is defined - ns := os.Getenv("DNSUTILS_OVERRIDE_NS") - if ns != "" { - address = ns - } - if network == "tcp" || network == "udp" { - var d net.Dialer - conn, err = d.DialContext(ctx, network, address) - return - } - err = fmt.Errorf("unsupported network protocol %s for DNS lookup", network) - return -} - func orderSRV(addrs []*net.SRV) (int, map[int]*net.SRV) { // Initialise the ordered map var o int |