package servlet import ( cssw "git.loafle.net/commons/server-go/socket/web" crpj "git.loafle.net/commons/rpc-go/protocol/json" "git.loafle.net/commons/server-go" "github.com/valyala/fasthttp" ogeg "git.loafle.net/overflow/gateway/external/grpc" "context" ) type RPCServlet interface { cssw.Servlet } type RPCServlets struct { cssw.Servlets } func init() { // member RSA file read } func (s *RPCServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) (*fasthttp.ResponseHeader, error) { // member auth token extraction // auth token parse // auth token valid // servletCtx set member return nil, nil } 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() grpcCTX := context.Background() for { select { case msg, ok := <-readChan: if !ok { return } // grpc exec method call src, _ := sc.NewRequest(msg) m := src.Method() p,_ := src.Params() r, err := ogeg.Exec(grpcCTX,m, p) b, err := src.NewResponse(r, err) writeChan <- b case <-stopChan: return } } }