From cdaa7e88a68e714edf841f9e9868ac10145b2649 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sun, 1 May 2022 02:38:54 -0700 Subject: [PATCH] Use reflectutil to convert argument if type does not match --- server/server.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/server.go b/server/server.go index ddd031a..af37c14 100644 --- a/server/server.go +++ b/server/server.go @@ -124,12 +124,11 @@ func (s *Server) execute(typ string, name string, arg any, c codec.Codec) (a any argVal := reflect.ValueOf(arg) // If argument's type does not match method's argument type if arg != nil && argVal.Type() != mtdType.In(1) { - // If it is possible to convert the arg to desired type - if argVal.CanConvert(mtdType.In(1)) { - // Convert and set arg to result - arg = argVal.Convert(mtdType.In(1)).Interface() + val, err = reflectutil.Convert(argVal, mtdType.In(1)) + if err != nil { + return nil, nil, err } - //TODO: Invalid value err + arg = val.Interface() } // Create new context