This repository was archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample.go
78 lines (63 loc) · 1.34 KB
/
example.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
72
73
74
75
76
77
78
package example_zoo
// it will be collect into zooSet
// use init to create initZoo method in wire.gen.go
// @autowire.init(set=zoo)
type Zoo struct {
Cat Cat
Dog Dog
Lion Lion
FlyAnimal FlyAnimal
ConfigField ConfigField
AnonymousConfigField2
Tiger
}
type (
// @autowire.init(set=zoo)
MiniZoo struct {
Cat Cat
FlyAnimal FlyAnimal
}
// it will be collect into animalsSet
// @autowire(set=animals)
Cat struct{}
// @autowire(set=animals,FlyAnimal)
Bird struct{}
FlyAnimal interface {
Fly()
}
// use provider func
Dog struct{}
// @autowire.config(set=config)
Config struct {
ConfigField ConfigField
AnonymousConfigField2
}
)
type (
ConfigField struct {
}
AnonymousConfigField2 struct {
}
)
// it will be collect into animalsSet
// user provider func
// @autowire(set=animals)
func ProvideDog() Dog {
return Dog{}
}
// it will be collect into animalsSet
// as it has a New method it will use NewLion as provider
// @autowire(set=animals)
type Lion struct{}
func NewLion() Lion {
return Lion{}
}
// it will be collect into animalsSet
// as it has a New method it will use NewLion as provider
// @autowire(set=animals,new=InitSomeTiger)
type Tiger struct{}
func InitSomeTiger() Tiger {
return Tiger{}
}
// it will be collect into animalsSet and wire as interface FlyAnimal
func (b Bird) Fly() {}