From 28a86a928252f9272ef6fc53b3e0802899827b5c Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 10 Apr 2018 02:04:28 +0900 Subject: [PATCH] ing --- servlet/rpc-servlet.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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 {