Call takes a receiver function with one or more arguments of the abstractions (interfaces). It invokes the receiver function and passes the related concretes.
(function interface{})
| 193 | // Call takes a receiver function with one or more arguments of the abstractions (interfaces). |
| 194 | // It invokes the receiver function and passes the related concretes. |
| 195 | func (c Container) Call(function interface{}) error { |
| 196 | receiverType := reflect.TypeOf(function) |
| 197 | if receiverType == nil || receiverType.Kind() != reflect.Func { |
| 198 | return errors.New("container: invalid function") |
| 199 | } |
| 200 | |
| 201 | arguments, err := c.arguments(function) |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | |
| 206 | result := reflect.ValueOf(function).Call(arguments) |
| 207 | |
| 208 | if len(result) == 0 { |
| 209 | return nil |
| 210 | } else if len(result) == 1 && result[0].CanInterface() { |
| 211 | if result[0].IsNil() { |
| 212 | return nil |
| 213 | } |
| 214 | if err, ok := result[0].Interface().(error); ok { |
| 215 | return err |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return errors.New("container: receiver function signature is invalid") |
| 220 | } |
| 221 | |
| 222 | // Resolve takes an abstraction (reference of an interface type) and fills it with the related concrete. |
| 223 | func (c Container) Resolve(abstraction interface{}) error { |