Use reflectutil to convert argument if type does not match
This commit is contained in:
		@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user