-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
99 lines (88 loc) · 1.27 KB
/
main.go
File metadata and controls
99 lines (88 loc) · 1.27 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"github.com/pubgo/dix/v2/dixglobal"
)
type Inline struct {
M *C1
}
type D struct {
M C
}
type (
C interface{}
C1 struct {
Name string
}
)
type Conf struct {
Data string
Inline
A *A
B *B
C C
D *D
D1 *D
D2 map[string]*D
D3 []*D
D4 map[string][]*D
}
type A struct {
Hello string
}
type B struct {
Hello string
}
func main() {
defer func() {
if r := recover(); r != nil {
err, ok := r.(error)
if !ok {
err = fmt.Errorf("panic: %v", r)
}
fmt.Printf("panic: %v\n", err)
}
}()
dixglobal.Provide(func() Conf {
return Conf{
A: &A{Hello: "hello-a"},
B: &B{Hello: "hello-b"},
C: "hello",
D: &D{
M: "hello",
},
D1: &D{
M: "hello d1",
},
D2: map[string]*D{
"default1": {
M: "hello d2",
},
},
D3: []*D{
{
M: "hello d3",
},
},
D4: map[string][]*D{
"default4": {
{
M: "hello d4",
},
},
},
Inline: Inline{M: &C1{Name: "c1"}},
}
})
dixglobal.Inject(func(a *A, b *B, cc []C, c1 *C1, c2 []*C1, d *D, dd []*D, dm map[string]*D, d5 map[string][]*D) {
fmt.Println(a.Hello)
fmt.Println(b.Hello)
fmt.Println(cc)
fmt.Println(c1)
fmt.Println(c2)
fmt.Println(d)
fmt.Println(dd)
fmt.Println(dm)
fmt.Println(d5)
})
}