如何从Go客户端获取gRPC服务器IP

I use docker-compose or kubernetes to deploy my gRPC servers, and want to get the server IP address in the go client. Does the gRPC library provides the get server-side IP method?

BTW, the scenario here is that i want to log the server ip to check whether nginx, envoy and other L7 load balancers make correct routing decisions.

It's an interesting question, as you already have knowledge about the gRPC server address prior to a client creation

conn, err := grpc.Dial(*serverAddr)
if err != nil {
    ...
}
defer conn.Close()
client := pb.NewRouteGuideClient(conn)

I don't believe there is a method for getting server IP in the standard gRPC library. If you use external load balancers/proxies (e.g. Nginx or Envoy) you can add the end server IP to the metadata on the server side

md := metadata.Pairs(
    "serverIP", "127.0.0.1",
)

The LB distributes the RPC call to one of the available backend servers that implement the actual logic for serving the call. The LB keeps track of load on each backend and implements algorithms for distributing load fairly. The clients themselves do not know about the backend servers. read more https://grpc.io/blog/loadbalancing

Remote Procedure Call (RPC) is a higher level abstraction, you shouldn't deal with networking using RPC.

If you're trying to implement client side load balancing you should consider load balancing within gRPC (https://github.com/grpc/grpc/blob/master/doc/load-balancing.md), which is a special protocol you have to implement.