diff --git a/servlet/rpc-servlet.go b/servlet/rpc-servlet.go index 31cbdda..8957f20 100644 --- a/servlet/rpc-servlet.go +++ b/servlet/rpc-servlet.go @@ -11,6 +11,7 @@ import ( og "git.loafle.net/overflow/gateway" ogeg "git.loafle.net/overflow/gateway/external/grpc" "github.com/valyala/fasthttp" + "google.golang.org/grpc/metadata" ) type RPCServlet interface { @@ -41,11 +42,8 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx, doneChan <- struct{}{} }() - sc := crpj.NewServerCodec() - - servletCtx.SetAttribute(og.SessionWriteChanKey, writeChan) - var ( + md metadata.MD src crp.ServerRequestCodec method string params []string @@ -54,6 +52,21 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx, replyBuff []byte err error ) + sc := crpj.NewServerCodec() + + _clientType := servletCtx.GetAttribute(og.SessionClientTypeKey) + _sessionID := servletCtx.GetAttribute(og.SessionIDKey) + _targetID := servletCtx.GetAttribute(og.SessionTargetIDKey) + + if nil != _clientType && nil != _sessionID && nil != _targetID { + md = metadata.Pairs( + og.GRPCClientTypeKey, _clientType.(og.ClientType).String(), + og.GRPCSessionIDKey, _sessionID.(string), + og.GRPCTargetIDKey, _targetID.(string), + ) + } + + servletCtx.SetAttribute(og.SessionWriteChanKey, writeChan) for { select { @@ -76,7 +89,7 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx, break } - grpcCtx = context.Background() + grpcCtx = metadata.NewOutgoingContext(context.Background(), md) grpcReply, err = ogeg.Exec(grpcCtx, method, params...) replyBuff, err = src.NewResponseWithString(grpcReply, err) if nil != err {