Documentation
¶
Overview ¶
Package resolver provides DNS A/AAAA resolution with optional ECS and configurable upstreams.
Index ¶
- Constants
- Variables
- func ResolveA(domain string, opts ...Option) ([]netip.Addr, error)
- func ResolveAAAA(domain string, opts ...Option) ([]netip.Addr, error)
- type Option
- func WithClient(c *fastdns.Client) Option
- func WithDNSServer(addr string) Option
- func WithDoH(endpoint string) Option
- func WithDoT(addr string) Option
- func WithDoTServerName(addr string, serverName string) Option
- func WithECS(prefixes ...string) Option
- func WithHTTPTransport(rt http.RoundTripper) Option
- func WithTCPServer(addr string) Option
- func WithTimeout(d time.Duration) Option
Constants ¶
const ( // DNS (UDP/TCP) DNSServerCloudflare1 = "1.1.1.1:53" DNSServerCloudflare2 = "1.0.0.1:53" DNSServerGoogle1 = "8.8.8.8:53" DNSServerGoogle2 = "8.8.4.4:53" DNSServerQuad9 = "9.9.9.9:53" // DoT (DNS over TLS) DoTCloudflare = "cloudflare-dns.com:853" DoTGoogle = "dns.google:853" DoTQuad9 = "dns.quad9.net:853" DotDnspod = "dot.pub:853" DoT360 = "dot.360.cn:853" // DoH (DNS over HTTPS) DoHCloudflare = "https://cloudflare-dns.com/dns-query" DoHGoogle = "https://dns.google/dns-query" DoHQuad9 = "https://dns.quad9.net/dns-query" DoHDnspod = "https://sm2.doh.pub/dns-query" DoH360 = "https://doh.360.cn/dns-query" )
Common upstreams for convenience.
Notes:
- DoT constants use hostnames (not IPs) so TLS SNI/verification works by default.
- DNS constants are "ip:53" or "host:53" strings for WithDNSServer/WithTCPServer.
Variables ¶
var (
ErrEmptyDomain = errors.New("resolver: empty domain")
)
Functions ¶
Types ¶
type Option ¶
type Option func(*options)
Option configures resolver behavior.
func WithClient ¶
WithClient uses a custom fastdns client. If set, it takes precedence over WithDNSServer/WithTCPServer/WithDoT/WithDoH.
func WithDNSServer ¶
WithDNSServer sets a UDP DNS upstream (e.g. "1.1.1.1", "1.1.1.1:53", "dns.google:53").
If addr is empty, it resets to the default from /etc/resolv.conf.
func WithDoH ¶
WithDoH sets a DNS-over-HTTPS (DoH) upstream endpoint.
Example: "https://1.1.1.1/dns-query".
func WithDoT ¶
WithDoT sets a DNS-over-TLS (DoT) upstream (default port 853).
It uses the host part of addr as TLS ServerName.
func WithDoTServerName ¶
WithDoTServerName sets a DoT upstream with an explicit TLS ServerName.
If serverName is empty, it uses the host part of addr.
func WithECS ¶
WithECS configures an EDNS Client Subnet (ECS) prefix list.
Each entry can be either a CIDR prefix (e.g. "1.2.3.0/24") or a single IP (e.g. "43.242.1.24"). For a single IP, resolver will use a default mask: IPv4 => /24, IPv6 => /56.
When provided, resolver will query once per prefix and merge results.
func WithHTTPTransport ¶
func WithHTTPTransport(rt http.RoundTripper) Option
WithHTTPTransport customizes the DoH HTTP transport.
It has effect only when used with WithDoH.
func WithTCPServer ¶
WithTCPServer sets a plain TCP DNS upstream (default port 53).
func WithTimeout ¶
WithTimeout sets the overall resolve timeout (applies to all attempts, including ECS fanout).
If d <= 0, it is treated as invalid.