From 80e88ca6aa307898a033ee44f7fe3253a716301d Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 27 Nov 2019 15:06:33 +0800 Subject: [PATCH] fix caller input nil panic --- pkg/cloudcommon/db/caller.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/cloudcommon/db/caller.go b/pkg/cloudcommon/db/caller.go index 9e05e6e848..5cb80a071a 100644 --- a/pkg/cloudcommon/db/caller.go +++ b/pkg/cloudcommon/db/caller.go @@ -88,17 +88,18 @@ func convertParams(params []*param) []reflect.Value { type param struct { pType reflect.Type - input reflect.Value + input interface{} } func newParam(pType reflect.Type, input interface{}) *param { return ¶m{ pType: pType, - input: reflect.ValueOf(input), + input: input, } } -func isJSONObject(val reflect.Value) (jsonutils.JSONObject, bool) { +func isJSONObject(input interface{}) (jsonutils.JSONObject, bool) { + val := reflect.ValueOf(input) obj, ok := val.Interface().(jsonutils.JSONObject) if !ok { return nil, false @@ -107,9 +108,12 @@ func isJSONObject(val reflect.Value) (jsonutils.JSONObject, bool) { } func (p *param) convert() reflect.Value { + if p.input == nil { + return reflect.New(p.pType).Elem() + } obj, ok := isJSONObject(p.input) if !ok { - return p.input + return reflect.ValueOf(p.input) } // generate object by type val := reflect.New(p.pType)