Build creates and starts a DNS resolver that watches the name resolution of
the target. Scheme returns the naming scheme of this resolver builder, which is "dns".
*dnsBuilder : google.golang.org/grpc/resolver.Builder
dnsResolver watches for the name resolution update for a non-IP target.cancelcontext.CancelFuncccresolver.ClientConnctxcontext.ContextenableServiceConfigboolhoststringportstringresolverinternal.NetResolver rn channel is used by ResolveNow() to force an immediate resolution of the
target. wg is used to enforce Close() to return after the watcher() goroutine has
finished. Otherwise, data race will be possible. [Race Example] in
dns_resolver_test we replace the real lookup functions with mocked ones to
facilitate testing. If Close() doesn't wait for watcher() goroutine
finishes, race detector sometimes will warn lookup (READ the lookup
function pointers) inside watcher() goroutine has data race with
replaceNetFunc (WRITE the lookup function pointers). Close closes the dnsResolver. ResolveNow invoke an immediate resolution of the target that this
dnsResolver watches.(*dnsResolver) lookup() (*resolver.State, error)(*dnsResolver) lookupHost(ctx context.Context) ([]resolver.Address, error)(*dnsResolver) lookupSRV(ctx context.Context) ([]resolver.Address, error)(*dnsResolver) lookupTXT(ctx context.Context) *serviceconfig.ParseResult(*dnsResolver) watcher()
*dnsResolver : google.golang.org/grpc/resolver.Resolver
formatIP returns an error if addr is not a valid textual representation of
an IP address. If addr is an IPv4 address, return the addr and error = nil.
If addr is an IPv6 address, return the addr enclosed in square brackets and
error = nil.
parseTarget takes the user input target string and default port, returns
formatted host and port info. If target doesn't specify a port, set the port
to be the defaultPort. If target is in IPv6 format and host-name is enclosed
in square brackets, brackets are stripped when setting the host.
examples:
target: "www.google.com" defaultPort: "443" returns host: "www.google.com", port: "443"
target: "ipv4-host:80" defaultPort: "443" returns host: "ipv4-host", port: "80"
target: "[ipv6-host]" defaultPort: "443" returns host: "ipv6-host", port: "443"
target: ":80" defaultPort: "443" returns host: "localhost", port: "80"
Package-Level Variables (total 6, in which 3 are exported)
EnableSRVLookups controls whether the DNS resolver attempts to fetch gRPCLB
addresses from SRV records. Must not be changed after init time.
MinResolutionInterval is the minimum interval at which re-resolutions are
allowed. This helps to prevent excessive re-resolution.
ResolvingTimeout specifies the maximum duration for a DNS resolution request.
If the timeout expires before a response is received, the request will be canceled.
It is recommended to set this value at application startup. Avoid modifying this variable
after initialization as it's not thread-safe for concurrent modification.