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.ContextdisableServiceConfigboolhoststringportstringresolvernetResolver
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 warns 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() ([]resolver.Address, error)(*dnsResolver) lookupSRV() ([]resolver.Address, error)(*dnsResolver) lookupTXT() *serviceconfig.ParseResult(*dnsResolver) watcher()
*dnsResolver : google.golang.org/grpc/resolver.Resolver
formatIP returns ok = false if addr is not a valid textual representation of an IP address.
If addr is an IPv4 address, return the addr and ok = true.
If addr is an IPv6 address, return the addr enclosed in square brackets and ok = true.
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 10, in which 1 are exported)
EnableSRVLookups controls whether the DNS resolver attempts to fetch gRPCLB
addresses from SRV records. Must not be changed after init time.
Addresses ending with a colon that is supposed to be the separator
between host and port is not allowed. E.g. "::" is a valid address as
it is an IPv6 address (host only) and "[::]:" is invalid as it ends with
a colon as the host and port separator