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.
CodePudding user response:
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
}