diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 0000000..58c773d --- /dev/null +++ b/glide.yaml @@ -0,0 +1,13 @@ +package: git.loafle.net/overflow/gateway_rpc +import: +- package: git.loafle.net/commons/rpc-go + subpackages: + - protocol/json +- package: git.loafle.net/commons/server-go + subpackages: + - socket/web +- package: git.loafle.net/overflow/gateway + subpackages: + - external/grpc +- package: github.com/valyala/fasthttp + version: ^20160617.0.0 diff --git a/servlet/rpc-servlet.go b/servlet/rpc-servlet.go index f45f5a4..8602087 100644 --- a/servlet/rpc-servlet.go +++ b/servlet/rpc-servlet.go @@ -1,13 +1,16 @@ package servlet import ( - cssw "git.loafle.net/commons/server-go/socket/web" + "context" + + logging "git.loafle.net/commons/logging-go" + crp "git.loafle.net/commons/rpc-go/protocol" crpj "git.loafle.net/commons/rpc-go/protocol/json" "git.loafle.net/commons/server-go" - - "github.com/valyala/fasthttp" + cssw "git.loafle.net/commons/server-go/socket/web" + og "git.loafle.net/overflow/gateway" ogeg "git.loafle.net/overflow/gateway/external/grpc" - "context" + "github.com/valyala/fasthttp" ) type RPCServlet interface { @@ -18,7 +21,7 @@ type RPCServlets struct { cssw.Servlets } -func init() { +func init() { // member RSA file read } @@ -31,18 +34,26 @@ func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Requ return nil, nil } -func (s *RPCServlets) Handle( - servletCtx server.ServletCtx, - stopChan <-chan struct{}, - doneChan chan<- struct{}, - readChan <-chan []byte, - writeChan chan<- []byte ) { +func (s *RPCServlets) Handle(servletCtx server.ServletCtx, + stopChan <-chan struct{}, doneChan chan<- struct{}, + readChan <-chan []byte, writeChan chan<- []byte) { defer func() { doneChan <- struct{}{} }() sc := crpj.NewServerCodec() + servletCtx.SetAttribute(og.SessionWriteChanKey, writeChan) + + var ( + src crp.ServerRequestCodec + method string + params []string + grpcCtx context.Context + grpcReply string + replyBuff []byte + err error + ) for { select { @@ -51,21 +62,28 @@ func (s *RPCServlets) Handle( return } // grpc exec method call - src, _ := sc.NewRequest(msg) + src, err = sc.NewRequest(msg) + if nil != err { + logging.Logger().Errore(err) + break + } - m := src.Method() - p,_ := src.Params() - grpcCTX := context.Background() + method = src.Method() + params, err = src.Params() + if nil != err { + logging.Logger().Errore(err) + break + } - r, err := ogeg.Exec(grpcCTX,m, p...) + grpcCtx = context.Background() + grpcReply, err = ogeg.Exec(grpcCTX, m, p...) + replyBuff, err = src.NewResponseWithString(grpcReply, err) - b, err := src.NewResponse(r, err) - - writeChan <- b + writeChan <- replyBuff case <-stopChan: return } } -} \ No newline at end of file +}