...
1
2
3
4 package grpc_middleware
5
6 import (
7 "context"
8
9 "google.golang.org/grpc"
10 )
11
12
13 type WrappedServerStream struct {
14 grpc.ServerStream
15
16 WrappedContext context.Context
17 }
18
19
20 func (w *WrappedServerStream) Context() context.Context {
21 return w.WrappedContext
22 }
23
24
25 func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream {
26 if existing, ok := stream.(*WrappedServerStream); ok {
27 return existing
28 }
29 return &WrappedServerStream{ServerStream: stream, WrappedContext: stream.Context()}
30 }
31
View as plain text