Involved Source Files Package delegatingresolver implements a resolver capable of resolving both
target URIs and proxy addresses.
Package-Level Type Names (total 3, none are exported)
/* sort exporteds by: | */
delegatingResolver manages both target URI and proxy address resolution by
delegating these tasks to separate child resolvers. Essentially, it acts as
an intermediary between the gRPC ClientConn and the child resolvers.
It implements the [resolver.Resolver] interface. // gRPC ClientConn childMu serializes calls into child resolvers. It also protects access to
the following fields. We do not hold both mu and childMu in the same goroutine. Avoid holding
both locks when calling into the child, as the child resolver may
synchronously callback into the channel. // protects all the fields below // resolved proxy addresses; empty if no proxy is configured // resolver for the proxy URI; nil if no proxy is configured // proxy URL, derived from proxy environment and target // parsed target URI to be resolved // resolver for the target URI, based on its scheme // state of the target resolver(*delegatingResolver) Close()(*delegatingResolver) ResolveNow(o resolver.ResolveNowOptions) proxyURIResolver creates a resolver for resolving proxy URIs using the "dns"
scheme. It adjusts the proxyURL to conform to the "dns:///" format and builds
a resolver with a wrappingClientConn to capture resolved addresses. updateClientConnStateLocked constructs a combined list of addresses by
pairing each proxy address with every target address of type TCP. For each
pair, it creates a new [resolver.Address] using the proxy address and
attaches the corresponding target address and user info as attributes. Target
addresses that are not of type TCP are appended to the list as-is. The
function returns nil if either resolver has not yet provided an update, and
returns the result of ClientConn.UpdateState once both resolvers have
provided at least one update. updateProxyResolverState updates the proxy resolver state by storing proxy
addresses and endpoints, marking the resolver as ready, and triggering a
state update if both proxy and target resolvers are ready. If the ClientConn
returns a non-nil error, it calls `ResolveNow()` on the target resolver. It
is a StateListener function of wrappingClientConn passed to the proxy
resolver. updateTargetResolverState is the StateListener function provided to the
target resolver via wrappingClientConn. It updates the resolver state and
marks the target resolver as ready. If the update includes at least one TCP
address and the proxy resolver has not yet been constructed, it initializes
the proxy resolver. A combined state update is triggered once both resolvers
are ready. If all addresses are non-TCP, it proceeds without waiting for the
proxy resolver. If ClientConn.UpdateState returns a non-nil error,
ResolveNow() is called on the proxy resolver.
*delegatingResolver : google.golang.org/grpc/resolver.Resolver
wrappingClientConn serves as an intermediary between the parent ClientConn
and the child resolvers created here. It implements the resolver.ClientConn
interface and is passed in that capacity to the child resolvers.parent*delegatingResolver Callback to deliver resolver state updates NewAddress intercepts the new resolved address from the child resolvers and
passes them to ClientConn. ParseServiceConfig parses the provided service config and returns an object
that provides the parsed config. ReportError intercepts errors from the child resolvers and passes them to
ClientConn. UpdateState receives resolver state updates and forwards them to the
appropriate listener function (either for the proxy or target resolver).
*wrappingClientConn : google.golang.org/grpc/resolver.ClientConn
Package-Level Functions (total 4, in which 1 is exported)
New creates a new delegating resolver that can create up to two child
resolvers:
- one to resolve the proxy address specified using the supported
environment variables. This uses the registered resolver for the "dns"
scheme. It is lazily built when a target resolver update contains at least
one TCP address.
- one to resolve the target URI using the resolver specified by the scheme
in the target URI or specified by the user using the WithResolvers dial
option. As a special case, if the target URI's scheme is "dns" and a
proxy is specified using the supported environment variables, the target
URI's path portion is used as the resolved address unless target
resolution is enabled using the dial option.
proxyURLForTarget determines the proxy URL for the given address based on the
environment. It can return the following:
- nil URL, nil error: No proxy is configured or the address is excluded
using the `NO_PROXY` environment variable or if req.URL.Host is
"localhost" (with or without // a port number)
- nil URL, non-nil error: An error occurred while retrieving the proxy URL.
- non-nil URL, nil error: A proxy is configured, and the proxy URL was
retrieved successfully without any errors.