package resolver import ( "context" "time" "github.com/miekg/dns" ) // DNSClient abstracts DNS wire-protocol exchanges so the resolver // can be tested without hitting real nameservers. type DNSClient interface { ExchangeContext( ctx context.Context, msg *dns.Msg, addr string, ) (*dns.Msg, time.Duration, error) } // udpClient wraps a real dns.Client for production use. type udpClient struct { timeout time.Duration } func (c *udpClient) ExchangeContext( ctx context.Context, msg *dns.Msg, addr string, ) (*dns.Msg, time.Duration, error) { cl := &dns.Client{Timeout: c.timeout} return cl.ExchangeContext(ctx, msg, addr) } // tcpClient wraps a real dns.Client using TCP. type tcpClient struct { timeout time.Duration } func (c *tcpClient) ExchangeContext( ctx context.Context, msg *dns.Msg, addr string, ) (*dns.Msg, time.Duration, error) { cl := &dns.Client{Net: "tcp", Timeout: c.timeout} return cl.ExchangeContext(ctx, msg, addr) }