ing
This commit is contained in:
parent
bd224840cf
commit
dfb3b53775
|
@ -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
|
||||
|
|
29
servlet.go
29
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) Stop() {
|
||||
if s.stopChan == nil {
|
||||
logging.Logger().Warn("Server: server must be started before stopping it")
|
||||
return
|
||||
}
|
||||
|
||||
func (s *rpcServlet) destroy(err error) {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user