Skip to content

Commit 2dbb62f

Browse files
authored
Expose grpc intercepter (#59)
This allows user of library to have control over the sequence of interceptor when already using chain interceptor
1 parent ed732d9 commit 2dbb62f

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

grpcreplay/grpcreplay.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func (r *Recorder) SetInitial(initial []byte) {
116116
// to enable recording.
117117
func (r *Recorder) DialOptions() []grpc.DialOption {
118118
return []grpc.DialOption{
119-
grpc.WithUnaryInterceptor(r.interceptUnary),
120-
grpc.WithStreamInterceptor(r.interceptStream),
119+
grpc.WithUnaryInterceptor(r.InterceptUnary),
120+
grpc.WithStreamInterceptor(r.InterceptStream),
121121
}
122122
}
123123

@@ -134,8 +134,8 @@ func (r *Recorder) Close() error {
134134
return nil
135135
}
136136

137-
// Intercepts all unary (non-stream) RPCs.
138-
func (r *Recorder) interceptUnary(ctx context.Context, method string, req, res interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
137+
// InterceptUnary intercepts all unary (non-stream) RPCs.
138+
func (r *Recorder) InterceptUnary(ctx context.Context, method string, req, res interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
139139
ereq := &entry{
140140
kind: pb.Entry_REQUEST,
141141
method: method,
@@ -201,7 +201,8 @@ func (r *Recorder) writeEntry(e *entry) (int, error) {
201201
return n, nil
202202
}
203203

204-
func (r *Recorder) interceptStream(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
204+
// InterceptStream intercepts all streaming RPCs.
205+
func (r *Recorder) InterceptStream(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
205206
cstream, serr := streamer(ctx, desc, cc, method, opts...)
206207
e := &entry{
207208
kind: pb.Entry_CREATE_STREAM,
@@ -426,8 +427,8 @@ func (rep *Replayer) Connection() (*grpc.ClientConn, error) {
426427
}()
427428
conn, err := grpc.NewClient(l.Addr().String(),
428429
append([]grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())},
429-
grpc.WithUnaryInterceptor(rep.interceptUnary),
430-
grpc.WithStreamInterceptor(rep.interceptStream))...,
430+
grpc.WithUnaryInterceptor(rep.InterceptUnary),
431+
grpc.WithStreamInterceptor(rep.InterceptStream))...,
431432
)
432433
if err != nil {
433434
return nil, err
@@ -453,7 +454,8 @@ func (rep *Replayer) Close() error {
453454
return nil
454455
}
455456

456-
func (rep *Replayer) interceptUnary(_ context.Context, method string, req, res interface{}, _ *grpc.ClientConn, _ grpc.UnaryInvoker, _ ...grpc.CallOption) error {
457+
// InterceptUnary intercepts all unary (non-stream) RPCs.
458+
func (rep *Replayer) InterceptUnary(_ context.Context, method string, req, res interface{}, _ *grpc.ClientConn, _ grpc.UnaryInvoker, _ ...grpc.CallOption) error {
457459
mreq := req.(proto.Message)
458460
if rep.opts.BeforeMatch != nil {
459461
if err := rep.opts.BeforeMatch(method, mreq); err != nil {
@@ -471,7 +473,8 @@ func (rep *Replayer) interceptUnary(_ context.Context, method string, req, res i
471473
return nil
472474
}
473475

474-
func (rep *Replayer) interceptStream(ctx context.Context, _ *grpc.StreamDesc, _ *grpc.ClientConn, method string, _ grpc.Streamer, _ ...grpc.CallOption) (grpc.ClientStream, error) {
476+
// InterceptStream intercepts all streaming RPCs.
477+
func (rep *Replayer) InterceptStream(ctx context.Context, _ *grpc.StreamDesc, _ *grpc.ClientConn, method string, _ grpc.Streamer, _ ...grpc.CallOption) (grpc.ClientStream, error) {
475478
return &repClientStream{ctx: ctx, rep: rep, method: method}, nil
476479
}
477480

0 commit comments

Comments
 (0)