ValidateServiceArg validates the argument type for a service method does not allow interfaces (and the obvious invalid types) arguments + return values have special handling for wave objects
(argType reflect.Type)
| 356 | // does not allow interfaces (and the obvious invalid types) |
| 357 | // arguments + return values have special handling for wave objects |
| 358 | func baseValidateServiceArg(argType reflect.Type) error { |
| 359 | if argType == waveObjUpdateRType { |
| 360 | // has special MarshalJSON method, so it is safe |
| 361 | return nil |
| 362 | } |
| 363 | switch argType.Kind() { |
| 364 | case reflect.Ptr, reflect.Slice, reflect.Array: |
| 365 | return baseValidateServiceArg(argType.Elem()) |
| 366 | case reflect.Map: |
| 367 | if argType.Key().Kind() != reflect.String { |
| 368 | return fmt.Errorf("invalid map key type %s", argType.Key()) |
| 369 | } |
| 370 | return baseValidateServiceArg(argType.Elem()) |
| 371 | case reflect.Struct: |
| 372 | for idx := 0; idx < argType.NumField(); idx++ { |
| 373 | if err := baseValidateServiceArg(argType.Field(idx).Type); err != nil { |
| 374 | return err |
| 375 | } |
| 376 | } |
| 377 | case reflect.Interface: |
| 378 | return fmt.Errorf("invalid argument type %s: contains interface", argType) |
| 379 | |
| 380 | case reflect.Chan, reflect.Func, reflect.Complex128, reflect.Complex64, reflect.Invalid, reflect.Uintptr, reflect.UnsafePointer: |
| 381 | return fmt.Errorf("invalid argument type %s", argType) |
| 382 | } |
| 383 | return nil |
| 384 | } |
| 385 | |
| 386 | func validateMethodReturnArg(retType reflect.Type) error { |
| 387 | // specifically allow waveobj.WaveObj, []waveobj.WaveObj, map[string]waveobj.WaveObj, and error |
no test coverage detected