Skip to content

Instantly share code, notes, and snippets.

@harunpeksen
Created March 11, 2022 15:55
Show Gist options
  • Save harunpeksen/a7139aafaaa7c1db3236b4f6f5a82bc0 to your computer and use it in GitHub Desktop.
Save harunpeksen/a7139aafaaa7c1db3236b4f6f5a82bc0 to your computer and use it in GitHub Desktop.
type wrappedStream struct {
grpc.ClientStream
}
func newWrappedStream(s grpc.ClientStream) grpc.ClientStream {
return &wrappedStream{s}
}
func (w *wrappedStream) RecvMsg(m interface{}) error {
.....
return w.ClientStream.RecvMsg(m)
}
func (w *wrappedStream) SendMsg(m interface{}) error {
.....
return w.ClientStream.SendMsg(m)
}
func exampleClientStreamInterceptor(ctx context.Context, desc *grpc.StreamDesc,
cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption)
(grpc.ClientStream, error) {
/*
some logic before client stream
*/
s, err := streamer(ctx, desc, cc, method, opts...)
return newWrappedStream(s), nil
}
func main() {
...
// Setting up a gRPC connection
conn, err := grpc.Dial(address, grpc.WithInsecure(),grpc.WithStreamInterceptor(exampleClientStreamInterceptor))
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment