invoke calls a function and its returned values. It only accepts one value and an optional error.
(function interface{})
| 95 | // invoke calls a function and its returned values. |
| 96 | // It only accepts one value and an optional error. |
| 97 | func (c Container) invoke(function interface{}) (interface{}, error) { |
| 98 | arguments, err := c.arguments(function) |
| 99 | if err != nil { |
| 100 | return nil, err |
| 101 | } |
| 102 | |
| 103 | values := reflect.ValueOf(function).Call(arguments) |
| 104 | if len(values) == 2 && values[1].CanInterface() { |
| 105 | if err, ok := values[1].Interface().(error); ok { |
| 106 | return values[0].Interface(), err |
| 107 | } |
| 108 | } |
| 109 | return values[0].Interface(), nil |
| 110 | } |
| 111 | |
| 112 | // arguments returns the list of resolved arguments for a function. |
| 113 | func (c Container) arguments(function interface{}) ([]reflect.Value, error) { |