mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-28 15:02:28 +00:00
8d763f450d
This is a follow-up on the `go fix` run in commit
0210c5fd92.
That commit recorded the automated updates.
This one applies further simplifications that are mechanical and do not
involve logic changes, but are outside of what `go fix` did.
It also removes some now-obsolete comments and statements.
36 lines
856 B
Go
36 lines
856 B
Go
// Support for overriding DNS lookups, for testing purposes.
|
|
// This is only used in tests, when the "dnsoverride" tag is active.
|
|
//
|
|
//go:build dnsoverride
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
dnsAddr = flag.String("testing__dns_addr", "127.0.0.1:9053",
|
|
"DNS server address to use, for testing purposes only")
|
|
)
|
|
|
|
var dialer = &net.Dialer{
|
|
// We're going to talk to localhost, so have a short timeout so we fail
|
|
// fast. Otherwise the callers might hang indefinitely when trying to
|
|
// dial the DNS server.
|
|
Timeout: 2 * time.Second,
|
|
}
|
|
|
|
func dial(ctx context.Context, network, address string) (net.Conn, error) {
|
|
return dialer.DialContext(ctx, network, *dnsAddr)
|
|
}
|
|
|
|
func init() {
|
|
// Override the resolver to talk with our local server for testing.
|
|
net.DefaultResolver.PreferGo = true
|
|
net.DefaultResolver.Dial = dial
|
|
}
|