Even simpler:

type serverStreamWrapper struct {
grpc.ServerStream

ctx context.Context
}

func (w *serverStreamWrapper) Context() context.Context { return w.ctx }

On Thursday, November 10, 2016 at 4:36:44 PM UTC-8, Francesco Lazzarino 
wrote:
>
> Thanks Qi, I'll look into that.
>
> If it helps anyone the wrapper looks like this:
>
> type serverStreamWrapper struct {
> ss  grpc.ServerStream
> ctx context.Context
> }
>
> func (w serverStreamWrapper) Context() context.Context        { return 
> w.ctx }
> func (w serverStreamWrapper) RecvMsg(msg interface{}) error   { return 
> w.ss.RecvMsg(msg) }
> func (w serverStreamWrapper) SendMsg(msg interface{}) error   { return 
> w.ss.SendMsg(msg) }
> func (w serverStreamWrapper) SendHeader(md metadata.MD) error { return 
> w.ss.SendHeader(md) }
> func (w serverStreamWrapper) SetHeader(md metadata.MD) error  { return 
> w.ss.SetHeader(md) }
> func (w serverStreamWrapper) SetTrailer(md metadata.MD)       { 
> w.ss.SetTrailer(md) }
>
> On Thursday, November 10, 2016 at 4:28:05 PM UTC-6, Francesco Lazzarino 
> wrote:
>>
>> Hi,
>>
>> I'm implementing a StreamServerInterceptor.
>>
>> func StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info 
>> *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
>>     // do some stuff, like attach a tracer to the context
>>     return handler(srv, ss)
>> }
>>
>> I can read the inbound ctx from ss.Context() but I can't figure out a 
>> way to replace it on the stream with a derivative Context. The best I can 
>> thing of is to wrap ss with some other grpc.ServerStream that does what 
>> I want. Is this the canonical way to do this?
>>
>> Thanks,
>>
>> -Franco
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/428b64fb-36e7-4e52-b202-d1abdab6f3ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to