ing
This commit is contained in:
parent
8bc041a548
commit
15614dd52a
13
glide.yaml
Normal file
13
glide.yaml
Normal 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
|
|
@ -1,13 +1,16 @@
|
||||||
package servlet
|
package servlet
|
||||||
|
|
||||||
import (
|
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"
|
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
||||||
"git.loafle.net/commons/server-go"
|
"git.loafle.net/commons/server-go"
|
||||||
|
cssw "git.loafle.net/commons/server-go/socket/web"
|
||||||
"github.com/valyala/fasthttp"
|
og "git.loafle.net/overflow/gateway"
|
||||||
ogeg "git.loafle.net/overflow/gateway/external/grpc"
|
ogeg "git.loafle.net/overflow/gateway/external/grpc"
|
||||||
"context"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RPCServlet interface {
|
type RPCServlet interface {
|
||||||
|
@ -31,18 +34,26 @@ func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Requ
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RPCServlets) Handle(
|
func (s *RPCServlets) Handle(servletCtx server.ServletCtx,
|
||||||
servletCtx server.ServletCtx,
|
stopChan <-chan struct{}, doneChan chan<- struct{},
|
||||||
stopChan <-chan struct{},
|
readChan <-chan []byte, writeChan chan<- []byte) {
|
||||||
doneChan chan<- struct{},
|
|
||||||
readChan <-chan []byte,
|
|
||||||
writeChan chan<- []byte ) {
|
|
||||||
defer func() {
|
defer func() {
|
||||||
doneChan <- struct{}{}
|
doneChan <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sc := crpj.NewServerCodec()
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -51,17 +62,24 @@ func (s *RPCServlets) Handle(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// grpc exec method call
|
// grpc exec method call
|
||||||
src, _ := sc.NewRequest(msg)
|
src, err = sc.NewRequest(msg)
|
||||||
|
if nil != err {
|
||||||
|
logging.Logger().Errore(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
m := src.Method()
|
method = src.Method()
|
||||||
p,_ := src.Params()
|
params, err = src.Params()
|
||||||
grpcCTX := context.Background()
|
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 <- replyBuff
|
||||||
|
|
||||||
writeChan <- b
|
|
||||||
case <-stopChan:
|
case <-stopChan:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user