From eac00359dbfb91b39edacfda3956ebef3d7c33a5 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 9 Nov 2017 17:38:02 +0900 Subject: [PATCH] ing --- gateway/handle.go | 2 +- gateway/server_handler.go | 2 +- gateway/server_handlers.go | 2 +- protocol/json/client_notify.go | 15 +++++++++++++-- protocol/json/server.go | 15 +++++++++++++-- protocol/registry_codec.go | 2 +- server_handler.go | 3 +-- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/gateway/handle.go b/gateway/handle.go index 5312efd..6ec4390 100644 --- a/gateway/handle.go +++ b/gateway/handle.go @@ -9,7 +9,7 @@ import ( func Handle(sh ServerHandler, codec protocol.ServerCodec, r io.Reader, w io.Writer) error { return rpc.Handle(sh, codec, r, w, func(codecReq protocol.ServerCodecRequest) (result interface{}, err error) { - var params []byte + var params []string if params, err = codecReq.Params(); nil != err { return nil, err } diff --git a/gateway/server_handler.go b/gateway/server_handler.go index 890ff70..88178f3 100644 --- a/gateway/server_handler.go +++ b/gateway/server_handler.go @@ -7,5 +7,5 @@ import ( type ServerHandler interface { rpc.ServerHandler - Invoke(method string, params []byte) (result interface{}, err error) + Invoke(method string, params []string) (result interface{}, err error) } diff --git a/gateway/server_handlers.go b/gateway/server_handlers.go index e695155..7f822f4 100644 --- a/gateway/server_handlers.go +++ b/gateway/server_handlers.go @@ -10,7 +10,7 @@ type ServerHandlers struct { rpc.ServerHandlers } -func (sh *ServerHandlers) Invoke(method string, params []byte) (result interface{}, err error) { +func (sh *ServerHandlers) Invoke(method string, params []string) (result interface{}, err error) { return nil, errors.New("Server: Handler method[Invoke] of Server is not implement") } diff --git a/protocol/json/client_notify.go b/protocol/json/client_notify.go index 1f40d16..a7a057d 100644 --- a/protocol/json/client_notify.go +++ b/protocol/json/client_notify.go @@ -62,9 +62,20 @@ func (ccn *ClientCodecNotify) ReadParams(args []interface{}) error { return ccn.err } -func (ccn *ClientCodecNotify) Params() ([]byte, error) { +func (ccn *ClientCodecNotify) Params() ([]string, error) { if ccn.err == nil && ccn.notify.Params != nil { - return *ccn.notify.Params, nil + var results []string + + if err := json.Unmarshal(*ccn.notify.Params, &results); err != nil { + ccn.err = &Error{ + Code: E_INVALID_REQ, + Message: err.Error(), + Data: ccn.notify.Params, + } + return nil, ccn.err + } + + return results, nil } return nil, ccn.err } diff --git a/protocol/json/server.go b/protocol/json/server.go index 7ad57c2..6f8f53b 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -202,9 +202,20 @@ func (scr *ServerCodecRequest) ReadParams(args []interface{}) error { return scr.err } -func (scr *ServerCodecRequest) Params() ([]byte, error) { +func (scr *ServerCodecRequest) Params() ([]string, error) { if scr.err == nil && scr.request.Params != nil { - return *scr.request.Params, nil + var results []string + + if err := json.Unmarshal(*scr.request.Params, &results); err != nil { + scr.err = &Error{ + Code: E_INVALID_REQ, + Message: err.Error(), + Data: scr.request.Params, + } + return nil, scr.err + } + + return results, nil } return nil, scr.err } diff --git a/protocol/registry_codec.go b/protocol/registry_codec.go index 421cd21..44babe7 100644 --- a/protocol/registry_codec.go +++ b/protocol/registry_codec.go @@ -9,6 +9,6 @@ type RegistryCodec interface { Method() string // Reads the request filling the RPC method args. ReadParams(args []interface{}) error - Params() ([]byte, error) + Params() ([]string, error) Complete() } diff --git a/server_handler.go b/server_handler.go index 855ea7e..c228a73 100644 --- a/server_handler.go +++ b/server_handler.go @@ -8,6 +8,7 @@ import ( type ServerHandler interface { RegisterCodec(codec protocol.ServerCodec, contentType string) + GetCodec(contentType string) (protocol.ServerCodec, error) OnPreRead(r io.Reader) OnPostRead(r io.Reader) @@ -17,6 +18,4 @@ type ServerHandler interface { OnPreWriteError(w io.Writer, err error) OnPostWriteError(w io.Writer, err error) - - GetCodec(contentType string) (protocol.ServerCodec, error) }