This commit is contained in:
crusader 2018-04-10 01:02:35 +09:00
parent 8bc041a548
commit 15614dd52a
2 changed files with 51 additions and 20 deletions

13
glide.yaml Normal file
View File

@ -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

View File

@ -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 {
@ -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,17 +62,24 @@ 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
}