This commit is contained in:
crusader 2018-03-20 14:21:44 +09:00
parent 5298f21b68
commit efea9e8ca6

View File

@ -2,10 +2,9 @@ package json
import ( import (
"encoding/json" "encoding/json"
"reflect"
"git.loafle.net/commons_go/rpc/codec" "git.loafle.net/commons_go/rpc/codec"
cur "git.loafle.net/commons_go/util/reflect" cuej "git.loafle.net/commons_go/util/encoding/json"
) )
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -34,8 +33,7 @@ func (cnc *ClientNotificationCodec) ReadParams(args []interface{}) error {
if cnc.err == nil && cnc.noti.Params != nil { if cnc.err == nil && cnc.noti.Params != nil {
// Note: if scr.request.Params is nil it's not an error, it's an optional member. // Note: if scr.request.Params is nil it's not an error, it's an optional member.
// JSON params structured object. Unmarshal to the args object. // JSON params structured object. Unmarshal to the args object.
var values []string if err := cuej.SetValueWithJSONStringArray(*cnc.noti.Params, args); nil != err {
if err := json.Unmarshal(*cnc.noti.Params, &values); err != nil {
cnc.err = &Error{ cnc.err = &Error{
Code: E_INVALID_REQ, Code: E_INVALID_REQ,
Message: err.Error(), Message: err.Error(),
@ -43,25 +41,7 @@ func (cnc *ClientNotificationCodec) ReadParams(args []interface{}) error {
} }
return cnc.err return cnc.err
} }
return nil
for indexI := 0; indexI < len(args); indexI++ {
value := values[indexI]
arg := args[indexI]
if cur.IsTypeKind(reflect.TypeOf(arg), reflect.String, true) {
arg = arg.(*string)
arg = &value
} else {
if err := json.Unmarshal([]byte(value), &arg); err != nil {
cnc.err = &Error{
Code: E_INVALID_REQ,
Message: err.Error(),
Data: cnc.noti.Params,
}
return cnc.err
}
}
}
} }
return cnc.err return cnc.err
} }