tree: 416419293010f51fcd5c6cbfc58a1c5c7beb2290 [path history] [tgz]
  2. client/
  3. server/

Name resolving

This examples shows how ClientConn can pick different name resolvers.

What is a name resolver

A name resolver can be seen as a map[service-name][]backend-ip. It takes a service name, and returns a list of IPs of the backends. A common used name resolver is DNS.

In this example, a resolver is created to resolve to localhost:50051.

Try it

go run server/main.go
go run client/main.go


The echo server is serving on “:50051”. Two clients are created, one is dialing to passthrough:///localhost:50051, while the other is dialing to example:/// Both of them can connect the server.

Name resolver is picked based on the scheme in the target string. See for the target syntax.

The first client picks the passthrough resolver, which takes the input, and use it as the backend addresses.

The second is connecting to service name Without a proper name resolver, this would fail. In the example it picks the example resolver that we installed. The example resolver can handle correctly by returning the backend address. So even though the backend IP is not set when ClientConn is created, the connection will be created to the correct backend.