(argType reflect.Type, jsonArg any)
| 200 | } |
| 201 | |
| 202 | func convertArgument(argType reflect.Type, jsonArg any) (any, error) { |
| 203 | if jsonArg == nil { |
| 204 | return reflect.Zero(argType).Interface(), nil |
| 205 | } |
| 206 | if isSpecialWaveArgType(argType) { |
| 207 | return convertSpecial(argType, jsonArg) |
| 208 | } |
| 209 | jsonType := reflect.TypeOf(jsonArg) |
| 210 | switch argType.Kind() { |
| 211 | case reflect.String: |
| 212 | if jsonType.Kind() == reflect.String { |
| 213 | return jsonArg, nil |
| 214 | } |
| 215 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 216 | |
| 217 | case reflect.Bool: |
| 218 | if jsonType.Kind() == reflect.Bool { |
| 219 | return jsonArg, nil |
| 220 | } |
| 221 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 222 | |
| 223 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, |
| 224 | reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, |
| 225 | reflect.Float32, reflect.Float64: |
| 226 | if jsonType.Kind() == reflect.Float64 { |
| 227 | return convertNumber(argType, jsonArg.(float64)) |
| 228 | } |
| 229 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 230 | |
| 231 | case reflect.Map: |
| 232 | if argType.Key().Kind() != reflect.String { |
| 233 | return nil, fmt.Errorf("invalid map key type %s", argType.Key()) |
| 234 | } |
| 235 | if jsonType.Kind() != reflect.Map { |
| 236 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 237 | } |
| 238 | return convertComplex(argType, jsonArg) |
| 239 | |
| 240 | case reflect.Slice: |
| 241 | if jsonType.Kind() != reflect.Slice { |
| 242 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 243 | } |
| 244 | return convertComplex(argType, jsonArg) |
| 245 | |
| 246 | case reflect.Struct: |
| 247 | if jsonType.Kind() != reflect.Map { |
| 248 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 249 | } |
| 250 | return convertComplex(argType, jsonArg) |
| 251 | |
| 252 | case reflect.Ptr: |
| 253 | if argType.Elem().Kind() != reflect.Struct { |
| 254 | return nil, fmt.Errorf("invalid pointer type %s", argType) |
| 255 | } |
| 256 | if jsonType.Kind() != reflect.Map { |
| 257 | return nil, fmt.Errorf("cannot convert %T to %s", jsonArg, argType) |
| 258 | } |
| 259 | return convertComplex(argType, jsonArg) |
no test coverage detected