...
1
18
19 package testutils
20
21 import (
22 "context"
23
24 "google.golang.org/grpc/stats"
25 )
26
27
28
29
30 type StubStatsHandler struct {
31 TagRPCF func(ctx context.Context, info *stats.RPCTagInfo) context.Context
32 HandleRPCF func(ctx context.Context, info stats.RPCStats)
33 TagConnF func(ctx context.Context, info *stats.ConnTagInfo) context.Context
34 HandleConnF func(ctx context.Context, info stats.ConnStats)
35 }
36
37
38 func (ssh *StubStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context {
39 if ssh.TagRPCF != nil {
40 return ssh.TagRPCF(ctx, info)
41 }
42 return ctx
43 }
44
45
46 func (ssh *StubStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
47 if ssh.HandleRPCF != nil {
48 ssh.HandleRPCF(ctx, rs)
49 }
50 }
51
52
53 func (ssh *StubStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context {
54 if ssh.TagConnF != nil {
55 return ssh.TagConnF(ctx, info)
56 }
57 return ctx
58 }
59
60
61 func (ssh *StubStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats) {
62 if ssh.HandleConnF != nil {
63 ssh.HandleConnF(ctx, cs)
64 }
65 }
66
View as plain text