-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
51 lines (47 loc) · 1.15 KB
/
system.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
package internal
import (
"context"
"os"
"github.com/antonio-muniz/alph/pkg/clock"
"github.com/antonio-muniz/alph/pkg/logger"
"github.com/antonio-muniz/alph/cmd/alph/internal/config"
"github.com/antonio-muniz/alph/cmd/alph/internal/storage/memory"
"github.com/antonio-muniz/alph/pkg/system"
"github.com/pkg/errors"
"github.com/sarulabs/di"
)
func System(_ctx context.Context) (system.System, error) {
builder, err := di.NewBuilder()
if err != nil {
return system.System{}, errors.WithStack(err)
}
builder.Add(
di.Def{
Name: "config",
Build: func(container di.Container) (interface{}, error) {
return config.Load(), nil
},
},
di.Def{
Name: "database",
Build: func(container di.Container) (interface{}, error) {
return memory.NewDatabase(), nil
},
},
di.Def{
Name: "clock",
Build: func(container di.Container) (interface{}, error) {
return clock.NewWorkingClock(), nil
},
},
di.Def{
Name: "logger",
Build: func(container di.Container) (interface{}, error) {
return logger.NewLogger(os.Stdout), nil
},
},
)
container := builder.Build()
system := system.New(container)
return system, nil
}