-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_iface.go
56 lines (48 loc) · 1.1 KB
/
provider_iface.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package di
import (
"fmt"
"reflect"
"github.com/goava/di/internal/reflection"
)
// providerInterface
type providerInterface struct {
source keyUniq
result key
}
// newProviderInterface
func newProviderInterface(uniq string, k key, as interface{}) (*providerInterface, error) {
iface, err := reflection.InspectInterfacePtr(as)
if err != nil {
return nil, err
}
if !k.Type.Implements(iface.Type) {
return nil, fmt.Errorf("%s not implement %s", k, iface.Type)
}
return &providerInterface{
source: keyUniq{k, uniq},
result: key{iface.Type, k.Name},
}, nil
}
// Type
func (p providerInterface) Type() reflect.Type {
return p.result.Type
}
// Name
func (p providerInterface) Name() string {
return p.result.Name
}
// ParameterList
func (p providerInterface) ParameterList() parameterList {
var plist parameterList
plist = append(plist, parameter{
uniq: p.source.uniq,
name: p.source.Name,
typ: p.source.Type,
optional: false,
})
return plist
}
// Provide
func (p providerInterface) Provide(values ...reflect.Value) (reflect.Value, func(), error) {
return values[0], nil, nil
}