resolver

package module
v0.0.0-...-fd74a75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package resolver provides DNS A/AAAA resolution with optional ECS and configurable upstreams.

Index

Constants

View Source
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

View Source
var (
	ErrEmptyDomain = errors.New("resolver: empty domain")
)

Functions

func ResolveA

func ResolveA(domain string, opts ...Option) ([]netip.Addr, error)

ResolveA resolves the A records for the given domain.

If ECS is provided via options, resolver will query once for each ECS prefix and return the union of all returned IPs.

func ResolveAAAA

func ResolveAAAA(domain string, opts ...Option) ([]netip.Addr, error)

ResolveAAAA resolves the AAAA records for the given domain.

If ECS is provided via options, resolver will query once for each ECS prefix and return the union of all returned IPs.

Types

type Option

type Option func(*options)

Option configures resolver behavior.

func WithClient

func WithClient(c *fastdns.Client) Option

WithClient uses a custom fastdns client. If set, it takes precedence over WithDNSServer/WithTCPServer/WithDoT/WithDoH.

func WithDNSServer

func WithDNSServer(addr string) Option

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

func WithDoH(endpoint string) Option

WithDoH sets a DNS-over-HTTPS (DoH) upstream endpoint.

Example: "https://1.1.1.1/dns-query".

func WithDoT

func WithDoT(addr string) Option

WithDoT sets a DNS-over-TLS (DoT) upstream (default port 853).

It uses the host part of addr as TLS ServerName.

func WithDoTServerName

func WithDoTServerName(addr string, serverName string) Option

WithDoTServerName sets a DoT upstream with an explicit TLS ServerName.

If serverName is empty, it uses the host part of addr.

func WithECS

func WithECS(prefixes ...string) Option

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

func WithTCPServer(addr string) Option

WithTCPServer sets a plain TCP DNS upstream (default port 53).

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the overall resolve timeout (applies to all attempts, including ECS fanout).

If d <= 0, it is treated as invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL