I am getting an error like this
reflect.Value.Convert: value of type string cannot be converted to type int
goroutine 6
When I am running this code
param := "1" // type string
ps := fn.In(i) // type int
if !reflect.TypeOf(param).ConvertibleTo(ps) {
fmt.Print("Could not convert parameter.
") // this is printed
}
convertedParam := reflect.ValueOf(param).Convert(ps)
Can I do this in some way without creating a switch/case and multiple lines of code for converting to each type? I am just looking for the easiest/best way to do this.