-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoffin.go
71 lines (59 loc) · 1.44 KB
/
coffin.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gone
import (
"reflect"
"sort"
)
// coffin represents a component container in the gone framework
type coffin struct {
name string
goner any
order int
onlyForName bool
forceReplace bool
defaultTypeMap map[reflect.Type]bool
lazyFill bool
needInitBeforeUse bool
isFill bool
isInit bool
provider *wrapProvider
}
func newCoffin(goner any) *coffin {
_, needInitBeforeUse := goner.(Initiator)
if !needInitBeforeUse {
_, needInitBeforeUse = goner.(InitiatorNoError)
}
provider := tryWrapGonerToProvider(goner)
if provider != nil {
needInitBeforeUse = true
}
if !needInitBeforeUse {
_, needInitBeforeUse = goner.(NamedProvider)
}
if !needInitBeforeUse {
_, needInitBeforeUse = goner.(StructFieldInjector)
}
return &coffin{
goner: goner,
defaultTypeMap: make(map[reflect.Type]bool),
needInitBeforeUse: needInitBeforeUse,
provider: provider,
}
}
func (c *coffin) isDefault(t reflect.Type) bool {
return c.defaultTypeMap[t]
}
// coffinList is a slice of coffin pointers that implements sort.Interface
type coffinList []*coffin
func (c coffinList) Len() int {
return len(c)
}
func (c coffinList) Less(i, j int) bool {
return c[i].order < c[j].order
}
func (c coffinList) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
// SortCoffins sorts a slice of coffins by their order
func SortCoffins(coffins []*coffin) {
sort.Sort(coffinList(coffins))
}