From d466ca204bf0da43916771bbb310f5270f624aab Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 3 Nov 2017 21:23:12 +0900 Subject: [PATCH] ing --- protocol/json/server.go | 25 ++++++++++++++++--------- registry.go | 7 +++++-- service_map.go | 20 +++++++++++++++----- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/protocol/json/server.go b/protocol/json/server.go index 9995583..8446066 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -3,7 +3,6 @@ package json import ( "encoding/json" "io" - "log" "sync" "git.loafle.net/commons_go/rpc/encode" @@ -177,20 +176,28 @@ func (scr *ServerCodecRequest) ReadParams(args []interface{}) error { // Data: scr.request.Params, // } // } - jss := make([]json.RawMessage, len(args)) - if err := json.Unmarshal(*scr.request.Params, &jss); err != nil { - log.Printf("err:%v", err) + raws := make([]json.RawMessage, len(args)) + if err := json.Unmarshal(*scr.request.Params, &raws); err != nil { + scr.err = &Error{ + Code: E_INVALID_REQ, + Message: err.Error(), + Data: scr.request.Params, + } + return scr.err } for indexI := 0; indexI < len(args); indexI++ { - js := jss[indexI] + raw := raws[indexI] arg := args[indexI] - if err := json.Unmarshal(js, &arg); err != nil { - log.Printf("err:%v", err) + if err := json.Unmarshal(raw, &arg); err != nil { + scr.err = &Error{ + Code: E_INVALID_REQ, + Message: err.Error(), + Data: scr.request.Params, + } + return scr.err } - } - } return scr.err } diff --git a/registry.go b/registry.go index 950cee4..b4044c5 100644 --- a/registry.go +++ b/registry.go @@ -86,8 +86,11 @@ func (rr *rpcRegistry) Invoke(codec protocol.RegistryCodec) (result interface{}, pCount := len(pInstances) in = make([]reflect.Value, pCount+1) for indexI := 0; indexI < pCount; indexI++ { - in[indexI+1] = pValues[indexI] - //in[indexI+1] = reflect.ValueOf(pInstances[indexI]).Convert(methodSpec.paramTypes[indexI]) + if pValues[indexI].Type().Kind() == reflect.Ptr && pValues[indexI].Type().Elem().Kind() != reflect.Struct { + in[indexI+1] = reflect.Indirect(pValues[indexI]) + } else { + in[indexI+1] = pValues[indexI] + } } } else { in = make([]reflect.Value, 1) diff --git a/service_map.go b/service_map.go index 2c2b329..9a249bb 100644 --- a/service_map.go +++ b/service_map.go @@ -54,11 +54,21 @@ func getValue(t reflect.Type) reflect.Value { rt = rt.Elem() } - rv := reflect.New(rt) - if rt.Kind() != reflect.Struct { - rv = reflect.Indirect(rv) - } - return rv + // rv := reflect.New(rt) + // if rt.Kind() != reflect.Struct { + // rv = reflect.Indirect(rv) + // } + + // var rv reflect.Value + + // switch rt.Kind() { + // case reflect.Slice: + // rv = reflect.New(reflect.SliceOf(rt.Elem())) + // default: + // rv = reflect.New(rt) + // } + + return reflect.New(rt) } // ----------------------------------------------------------------------------