-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
41 lines (37 loc) · 884 Bytes
/
main.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
package main
import (
"fmt"
. "github.com/vlorc/gioc"
. "github.com/vlorc/gioc/module"
. "github.com/vlorc/gioc/module/operation"
)
type Personal struct {
name string `inject:"'name'"`
age *int `inject:"'age' default"`
gender int `inject:"'gender' optional"`
email string `inject:"'email' optional"`
}
// config.go
var ConfigModule = NewModuleFactory(
Export(
Mapping(map[string]interface{}{
"id": int64(123),
"name": "admin",
"gender": 1,
"email": "xxx@163.com",
}),
),
)
// main.go
func main() {
NewRootModule(
Import(ConfigModule),
Bootstrap(func(param struct {
Id int64 `inject:"lower"`
Strings []string `inject:"extends"`
Personal func() *Personal `inject:"lazy extends"`
}) {
fmt.Println(param.Strings, "id:", param.Id, "name:", (*param.Personal()).name, *param.Personal())
}),
)
}