-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
41 lines (37 loc) · 777 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 (
. "github.com/vlorc/gioc"
. "github.com/vlorc/gioc/module"
. "github.com/vlorc/gioc/module/operation"
)
type User struct {
Id int64 `inject:"lower"`
personal *struct {
name string
age int `inject:"default(99)"`
gender int `inject:"optional"`
email string `inject:"optional"`
} `inject:"extends"`
}
// config.go
var ConfigModule = NewModuleFactory(
Export(
Mapping(map[string]interface{}{
"id": int64(123),
"name": "admin_001",
"gender": 1,
"email": "[email protected]",
}),
),
)
// main.go
func main() {
NewRootModule(
Import(ConfigModule),
Bootstrap(func(param struct {
user User `inject:"extends"`
}) {
println("id: ", param.user.Id, " name: ", (*param.user.personal).name)
}),
)
}