blob: 2b7518e1c770efd411438f6dde9e3fd4455d96f1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package httpbinding
import (
"fmt"
"reflect"
)
func reflectCall(funcValue reflect.Value, args []interface{}) error {
argValues := make([]reflect.Value, len(args))
for i, v := range args {
value := reflect.ValueOf(v)
argValues[i] = value
}
retValues := funcValue.Call(argValues)
if len(retValues) > 0 {
errValue := retValues[0]
if typeName := errValue.Type().Name(); typeName != "error" {
panic(fmt.Sprintf("expected first return argument to be error but got %v", typeName))
}
if errValue.IsNil() {
return nil
}
if err, ok := errValue.Interface().(error); ok {
return err
}
panic(fmt.Sprintf("expected %v to return error type, but got %v", funcValue.Type().String(), retValues[0].Type().String()))
}
return nil
}
|