Use reflectutil to convert argument if type does not match

This commit is contained in:
Elara 2022-05-01 02:38:54 -07:00
parent f031e32a25
commit cdaa7e88a6
1 changed files with 4 additions and 5 deletions

View File

@ -124,12 +124,11 @@ func (s *Server) execute(typ string, name string, arg any, c codec.Codec) (a any
argVal := reflect.ValueOf(arg) argVal := reflect.ValueOf(arg)
// If argument's type does not match method's argument type // If argument's type does not match method's argument type
if arg != nil && argVal.Type() != mtdType.In(1) { if arg != nil && argVal.Type() != mtdType.In(1) {
// If it is possible to convert the arg to desired type val, err = reflectutil.Convert(argVal, mtdType.In(1))
if argVal.CanConvert(mtdType.In(1)) { if err != nil {
// Convert and set arg to result return nil, nil, err
arg = argVal.Convert(mtdType.In(1)).Interface()
} }
//TODO: Invalid value err arg = val.Interface()
} }
// Create new context // Create new context