Categorygithub.com/johnstarich/go/dns
modulepackage
0.2.4
Repository: https://github.com/johnstarich/go.git
Documentation: pkg.go.dev

# README

dns

NOTE: This module is obsolete as of Go 1.20. Go now uses the native macOS DNS resolver!

Implements a working macOS DNS resolver (really just a Dialer) for projects that must cross-compile from Linux systems or just don't want CGO.

In my experience, it is common to disable CGO for macOS CI builds. However, there's been a few issues with that. This library adds a drop-in replacement for Go's net.DefaultResolver to fill the gap.

import _ "github.com/johnstarich/go/dns/init"

This resolver reads the system's full DNS configuration and attempts to find the a successful nameserver. First, the dialer reaches out to the default nameserver. If the response isn't fast enough, more nameservers are attempted simultaneously.

On non-macOS builds a normal resolver is used, so this is safe to use for multi-platform builds.

Thoughts or questions? Please open an issue to discuss.

Debugging

Sometimes correct DNS results depends on nameservers being tried in a very specific order. If you see the wrong nameserver's results, try tuning the Config's timing settings.

For example, if the first nameserver is likely correct but is slow to respond, then increase the InitialNameserverDelay to compensate.

# Packages

Package init provides a convenient side-effecting import to set the custom DNS resolver.
Package scutil provides a complete model and parser for 'scutil --dns' output.
Package staggercast implements a one-to-many net.Conn for easy scattering of the same request to multiple endpoints with control on when new connections are attempted.
Package testhelpers contains a test DNS server lifecycle manager.

# Functions

New returns a default DNS resolver for this runtime.
NewWithConfig returns a DNS resolver with the given config for this runtime.

# Structs

Config contains options for configuring a DNS resolver.