'How to get message value in gRPC stream interceptor
I have implement a gRPC stream interceptor in Server like this:
// Service define:
// rpc searchProducts(google.protobuf.StringValue) returns (stream Product);
func (w *wrappedStream) RecvMsg(m interface{}) error {
log.Printf("%T, %v", m, m)
return w.ServerStream.RecvMsg(m)
}
// Log print:
// *wrapperspb.StringValue,
It can print the message type using %T correctly, but the message value printing by %v is just a blank.
I'm sure that Server received the right message, because it replied Client the right thing.
The interceptor wrapper RecvMsg is not working in Client too.
Solution 1:[1]
w.ServerStream.RecvMsg(m) will unmarshall data into m, just move print after RecvMsg() call.
func (w *wrappedStream) RecvMsg(m interface{}) error {
err := w.ServerStream.RecvMsg(m)
log.Printf("%T, %v", m, m)
return err
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | medasx |
