Call will attempt to call this bound method with the given args
(args []interface{})
| 60 | |
| 61 | // Call will attempt to call this bound method with the given args |
| 62 | func (b *BoundMethod) Call(args []interface{}) (interface{}, error) { |
| 63 | // Check inputs |
| 64 | expectedInputLength := len(b.Inputs) |
| 65 | actualInputLength := len(args) |
| 66 | if expectedInputLength != actualInputLength { |
| 67 | return nil, fmt.Errorf("%s takes %d inputs. Received %d", b.Path.FullName(), expectedInputLength, actualInputLength) |
| 68 | } |
| 69 | |
| 70 | /** Convert inputs to reflect values **/ |
| 71 | |
| 72 | // Create slice for the input arguments to the method call |
| 73 | callArgs := make([]reflect.Value, expectedInputLength) |
| 74 | |
| 75 | // Iterate over given arguments |
| 76 | for index, arg := range args { |
| 77 | // Save the converted argument |
| 78 | callArgs[index] = reflect.ValueOf(arg) |
| 79 | } |
| 80 | |
| 81 | // Do the call |
| 82 | callResults := b.Method.Call(callArgs) |
| 83 | |
| 84 | //** Check results **// |
| 85 | var returnValue interface{} |
| 86 | var err error |
| 87 | |
| 88 | switch b.OutputCount() { |
| 89 | case 1: |
| 90 | // Loop over results and determine if the result |
| 91 | // is an error or not |
| 92 | for _, result := range callResults { |
| 93 | interfac := result.Interface() |
| 94 | temp, ok := interfac.(error) |
| 95 | if ok { |
| 96 | err = temp |
| 97 | } else { |
| 98 | returnValue = interfac |
| 99 | } |
| 100 | } |
| 101 | case 2: |
| 102 | returnValue = callResults[0].Interface() |
| 103 | if temp, ok := callResults[1].Interface().(error); ok { |
| 104 | err = temp |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return returnValue, err |
| 109 | } |
no test coverage detected