From dfb3b5377505e4bd31290ad706d2c25e211e3ca5 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 9 Mar 2018 18:11:03 +0900 Subject: [PATCH] ing --- protocol/json/server_request.go | 18 ++++++++++++++++-- servlet.go | 31 +++++++++++-------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/protocol/json/server_request.go b/protocol/json/server_request.go index 4935031..0e1b593 100644 --- a/protocol/json/server_request.go +++ b/protocol/json/server_request.go @@ -135,9 +135,9 @@ func (src *ServerRequestCodec) ReadParams(args []interface{}) error { func (src *ServerRequestCodec) Params() ([]string, error) { if src.err == nil && src.req.Params != nil { - var results []string + var values []interface{} - if err := json.Unmarshal(*src.req.Params, &results); err != nil { + if err := json.Unmarshal(*src.req.Params, &values); err != nil { src.err = &Error{ Code: E_INVALID_REQ, Message: err.Error(), @@ -146,6 +146,20 @@ func (src *ServerRequestCodec) Params() ([]string, error) { return nil, src.err } + var results []string + for _, v := range values { + b, err := json.Marshal(v) + if nil != err { + src.err = &Error{ + Code: E_INVALID_REQ, + Message: err.Error(), + Data: src.req.Params, + } + return nil, src.err + } + results = append(results, string(b)) + } + return results, nil } return nil, src.err diff --git a/servlet.go b/servlet.go index 76d3885..da1afd1 100644 --- a/servlet.go +++ b/servlet.go @@ -42,6 +42,10 @@ type rpcServlet struct { stopWg sync.WaitGroup } +func (s *rpcServlet) Context() ServletContext { + return s.ctx +} + func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan chan<- error) error { if nil == s.sh { panic("Servlet: servlet handler must be specified.") @@ -80,17 +84,6 @@ func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan cha return nil } -func (s *rpcServlet) Stop() { - if s.stopChan == nil { - logging.Logger().Warn("Server: server must be started before stopping it") - return - } - - close(s.stopChan) - - s.destroy(nil) -} - func (s *rpcServlet) Send(method string, args ...interface{}) (err error) { noti := ¬ification{ method: method, @@ -105,11 +98,12 @@ func (s *rpcServlet) Send(method string, args ...interface{}) (err error) { return nil } -func (s *rpcServlet) Context() ServletContext { - return s.ctx -} - -func (s *rpcServlet) destroy(err error) { +func (s *rpcServlet) Stop() { + if s.stopChan == nil { + logging.Logger().Warn("Server: server must be started before stopping it") + return + } + close(s.stopChan) s.stopWg.Wait() s.sh.Destroy(s.ctx) @@ -120,8 +114,6 @@ func (s *rpcServlet) destroy(err error) { s.serverCodec = nil logging.Logger().Info(fmt.Sprintf("Servlet is stopped")) - - s.doneChan <- err } func handleServlet(s *rpcServlet) { @@ -131,7 +123,7 @@ func handleServlet(s *rpcServlet) { defer func() { s.stopWg.Done() - s.destroy(err) + s.doneChan <- err }() subStopChan := make(chan struct{}) @@ -158,7 +150,6 @@ func handleServlet(s *rpcServlet) { if err != nil { logging.Logger().Error(fmt.Sprintf("RPC Server: servlet error %v", err)) } - } func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {