| 76 | } |
| 77 | |
| 78 | func (c Container) validateResolverFunction(funcType reflect.Type) error { |
| 79 | retCount := funcType.NumOut() |
| 80 | |
| 81 | if retCount == 0 || retCount > 2 { |
| 82 | return errors.New("container: resolver function signature is invalid - it must return abstract, or abstract and error") |
| 83 | } |
| 84 | |
| 85 | resolveType := funcType.Out(0) |
| 86 | for i := 0; i < funcType.NumIn(); i++ { |
| 87 | if funcType.In(i) == resolveType { |
| 88 | return fmt.Errorf("container: resolver function signature is invalid - depends on abstract it returns") |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | // invoke calls a function and its returned values. |
| 96 | // It only accepts one value and an optional error. |