-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
57 lines (46 loc) · 987 Bytes
/
options.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
57
package injector
import "reflect"
type Options struct {
Alias string
Scope string
}
type Option func(*Options)
func WithAlias(alias string) Option {
return func(o *Options) {
o.Alias = alias
}
}
func WithScope(scope string) Option {
return func(o *Options) {
o.Scope = scope
}
}
type InvokeOptions struct {
InvokeInfo []*InvokeInfo
}
type InvokeInfo struct {
t reflect.Type
optional, alias, scope string
}
func NewInvokeInfo(v interface{}, scope, alias, optional string) *InvokeInfo {
return &InvokeInfo{
t: reflect.TypeOf(v),
optional: optional,
alias: alias,
scope: scope,
}
}
type InvokeOption func(*InvokeOptions)
func WithInvokeInfo(info ...*InvokeInfo) InvokeOption {
return func(o *InvokeOptions) {
o.InvokeInfo = append(o.InvokeInfo, info...)
}
}
func (i *InvokeOptions) GetInvokeInfo(t reflect.Type) *InvokeInfo {
for _, info := range i.InvokeInfo {
if info.t == t {
return info
}
}
return nil
}