diff --git a/clientconn.go b/clientconn.go index 56e81973..9b035e8f 100644 --- a/clientconn.go +++ b/clientconn.go @@ -580,6 +580,12 @@ func (cc *ClientConn) ChannelzMetric() *channelz.ChannelInternalMetric { } } +// Target returns the target string of the ClientConn. +// This is an EXPERIMENTAL API. +func (cc *ClientConn) Target() string { + return cc.target +} + func (cc *ClientConn) incrCallsStarted() { cc.czmu.Lock() cc.callsStarted++ diff --git a/clientconn_test.go b/clientconn_test.go index 7f489ed6..f2614dec 100644 --- a/clientconn_test.go +++ b/clientconn_test.go @@ -689,3 +689,15 @@ func TestDisableServiceConfigOption(t *testing.T) { t.Fatalf("want: method (\"/foo/bar/\") config to be empty, got: %v", m) } } + +func TestGetClientConnTarget(t *testing.T) { + addr := "nonexist:///non.existent" + cc, err := Dial(addr, WithInsecure()) + if err != nil { + t.Fatalf("Dial(%s, _) = _, %v, want _, ", addr, err) + } + defer cc.Close() + if cc.Target() != addr { + t.Fatalf("Target() = %s, want %s", cc.Target(), addr) + } +}