Skip to content

Commit 980d9e0

Browse files
authored
ClientConn: add Target() returning target string (#2233)
1 parent 445634b commit 980d9e0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clientconn.go

+6
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,12 @@ func (cc *ClientConn) ChannelzMetric() *channelz.ChannelInternalMetric {
580580
}
581581
}
582582

583+
// Target returns the target string of the ClientConn.
584+
// This is an EXPERIMENTAL API.
585+
func (cc *ClientConn) Target() string {
586+
return cc.target
587+
}
588+
583589
func (cc *ClientConn) incrCallsStarted() {
584590
cc.czmu.Lock()
585591
cc.callsStarted++

clientconn_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,15 @@ func TestDisableServiceConfigOption(t *testing.T) {
689689
t.Fatalf("want: method (\"/foo/bar/\") config to be empty, got: %v", m)
690690
}
691691
}
692+
693+
func TestGetClientConnTarget(t *testing.T) {
694+
addr := "nonexist:///non.existent"
695+
cc, err := Dial(addr, WithInsecure())
696+
if err != nil {
697+
t.Fatalf("Dial(%s, _) = _, %v, want _, <nil>", addr, err)
698+
}
699+
defer cc.Close()
700+
if cc.Target() != addr {
701+
t.Fatalf("Target() = %s, want %s", cc.Target(), addr)
702+
}
703+
}

0 commit comments

Comments
 (0)