@@ -31,7 +31,7 @@ type Options struct {
3131
3232 // Metrics holds optional metrics the client will populate. If nil, no
3333 // metrics are recorded.
34- Metrics * drpcmetrics.ClientMetrics
34+ Metrics drpcmetrics.ClientMetrics
3535}
3636
3737// Conn is a drpc client connection.
@@ -41,8 +41,7 @@ type Conn struct {
4141 mu sync.Mutex
4242 wbuf []byte
4343
44- stats map [string ]* drpcstats.Stats // TODO (server): deprecate stats
45- metrics drpcmetrics.ClientMetrics
44+ stats map [string ]* drpcstats.Stats // TODO (server): deprecate stats
4645}
4746
4847var _ drpc.Conn = (* Conn )(nil )
@@ -57,7 +56,8 @@ func NewWithOptions(tr drpc.Transport, opts Options) *Conn {
5756 tr : tr ,
5857 }
5958
60- c .initClientMetrics (opts .Metrics , tr )
59+ c .tr = drpcmetrics .ToMeteredTransport (tr , opts .Metrics .BytesSent ,
60+ opts .Metrics .BytesRecv )
6161
6262 if opts .CollectStats {
6363 drpcopts .SetManagerStatsCB (& opts .Manager .Internal , c .getStats )
@@ -69,17 +69,6 @@ func NewWithOptions(tr drpc.Transport, opts Options) *Conn {
6969 return c
7070}
7171
72- // initClientMetrics copies the caller-supplied metrics into the conn and
73- // wraps the transport with a metered transport if metrics are provided.
74- func (c * Conn ) initClientMetrics (metrics * drpcmetrics.ClientMetrics , tr drpc.Transport ) {
75- if metrics != nil {
76- c .metrics = * metrics
77- mt := drpcmetrics .NewMeteredTransport (tr , c .metrics .BytesSent ,
78- c .metrics .BytesRecv )
79- c .tr = mt
80- }
81- }
82-
8372// Stats returns the collected stats grouped by rpc.
8473func (c * Conn ) Stats () map [string ]drpcstats.Stats {
8574 c .mu .Lock ()
@@ -121,7 +110,9 @@ func (c *Conn) Close() (err error) { return c.man.Close() }
121110
122111// Invoke issues the rpc on the transport serializing in, waits for a response, and
123112// deserializes it into out. Only one Invoke or Stream may be open at a time.
124- func (c * Conn ) Invoke (ctx context.Context , rpc string , enc drpc.Encoding , in , out drpc.Message ) (err error ) {
113+ func (c * Conn ) Invoke (
114+ ctx context.Context , rpc string , enc drpc.Encoding , in , out drpc.Message ,
115+ ) (err error ) {
125116 defer func () { err = drpc .ToRPCErr (err ) }()
126117
127118 var metadata []byte
@@ -153,7 +144,14 @@ func (c *Conn) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, ou
153144 return nil
154145}
155146
156- func (c * Conn ) doInvoke (stream * drpcstream.Stream , enc drpc.Encoding , rpc string , data []byte , metadata []byte , out drpc.Message ) (err error ) {
147+ func (c * Conn ) doInvoke (
148+ stream * drpcstream.Stream ,
149+ enc drpc.Encoding ,
150+ rpc string ,
151+ data []byte ,
152+ metadata []byte ,
153+ out drpc.Message ,
154+ ) (err error ) {
157155 if len (metadata ) > 0 {
158156 if err := stream .RawWrite (drpcwire .KindInvokeMetadata , metadata ); err != nil {
159157 return err
@@ -176,7 +174,9 @@ func (c *Conn) doInvoke(stream *drpcstream.Stream, enc drpc.Encoding, rpc string
176174
177175// NewStream begins a streaming rpc on the connection. Only one Invoke or Stream may
178176// be open at a time.
179- func (c * Conn ) NewStream (ctx context.Context , rpc string , enc drpc.Encoding ) (_ drpc.Stream , err error ) {
177+ func (c * Conn ) NewStream (
178+ ctx context.Context , rpc string , enc drpc.Encoding ,
179+ ) (_ drpc.Stream , err error ) {
180180 defer func () { err = drpc .ToRPCErr (err ) }()
181181
182182 var metadata []byte
0 commit comments