Created
March 11, 2022 15:55
-
-
Save harunpeksen/a7139aafaaa7c1db3236b4f6f5a82bc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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