ing
This commit is contained in:
parent
3b15bbd349
commit
5298f21b68
|
@ -5,3 +5,4 @@ import:
|
||||||
- package: git.loafle.net/commons_go/server
|
- package: git.loafle.net/commons_go/server
|
||||||
- package: gopkg.in/natefinch/npipe.v2
|
- package: gopkg.in/natefinch/npipe.v2
|
||||||
- package: git.loafle.net/commons_go/websocket_fasthttp
|
- package: git.loafle.net/commons_go/websocket_fasthttp
|
||||||
|
- package: git.loafle.net/commons_go/util
|
||||||
|
|
|
@ -2,8 +2,10 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -32,8 +34,8 @@ 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.
|
||||||
raws := make([]json.RawMessage, len(args))
|
var values []string
|
||||||
if err := json.Unmarshal(*cnc.noti.Params, &raws); err != nil {
|
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,9 +45,14 @@ func (cnc *ClientNotificationCodec) ReadParams(args []interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for indexI := 0; indexI < len(args); indexI++ {
|
for indexI := 0; indexI < len(args); indexI++ {
|
||||||
raw := raws[indexI]
|
value := values[indexI]
|
||||||
arg := args[indexI]
|
arg := args[indexI]
|
||||||
if err := json.Unmarshal(raw, &arg); err != nil {
|
|
||||||
|
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{
|
cnc.err = &Error{
|
||||||
Code: E_INVALID_REQ,
|
Code: E_INVALID_REQ,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
|
@ -55,6 +62,7 @@ func (cnc *ClientNotificationCodec) ReadParams(args []interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return cnc.err
|
return cnc.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,20 +95,8 @@ func (src *ServerRequestCodec) ReadParams(args []interface{}) error {
|
||||||
if src.err == nil && src.req.Params != nil {
|
if src.err == nil && src.req.Params != nil {
|
||||||
// Note: if src.req.Params is nil it's not an error, it's an optional member.
|
// Note: if src.req.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 []json.RawMessage
|
||||||
// if err := json.Unmarshal(*src.req.Params, &args); err != nil {
|
if err := json.Unmarshal(*src.req.Params, &values); err != nil {
|
||||||
// // Clearly JSON params is not a structured object,
|
|
||||||
// // fallback and attempt an unmarshal with JSON params as
|
|
||||||
// // array value and RPC params is struct. Unmarshal into
|
|
||||||
// // array containing the request struct.
|
|
||||||
// src.err = &Error{
|
|
||||||
// Code: E_INVALID_REQ,
|
|
||||||
// Message: err.Error(),
|
|
||||||
// Data: src.req.Params,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
raws := make([]json.RawMessage, len(args))
|
|
||||||
if err := json.Unmarshal(*src.req.Params, &raws); err != nil {
|
|
||||||
src.err = &Error{
|
src.err = &Error{
|
||||||
Code: E_INVALID_REQ,
|
Code: E_INVALID_REQ,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
|
@ -118,9 +106,7 @@ func (src *ServerRequestCodec) ReadParams(args []interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for indexI := 0; indexI < len(args); indexI++ {
|
for indexI := 0; indexI < len(args); indexI++ {
|
||||||
raw := raws[indexI]
|
if err := json.Unmarshal(values[indexI], &args[indexI]); err != nil {
|
||||||
arg := args[indexI]
|
|
||||||
if err := json.Unmarshal(raw, &arg); err != nil {
|
|
||||||
src.err = &Error{
|
src.err = &Error{
|
||||||
Code: E_INVALID_REQ,
|
Code: E_INVALID_REQ,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user