-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (61 loc) · 2.17 KB
/
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
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
package main
import (
"context"
"github.com/dmibod/kanban/shared/tools/db/mongo"
"time"
"github.com/go-chi/chi"
"github.com/dmibod/kanban/cmd/shared"
"github.com/dmibod/kanban/command"
"github.com/dmibod/kanban/notify"
"github.com/dmibod/kanban/process"
"github.com/dmibod/kanban/query"
"github.com/dmibod/kanban/update"
)
func main() {
l := shared.CreateLogger("[KANBAN.] ")
c, cancel := context.WithCancel(context.Background())
sess := shared.CreateSessionFactory()
prov := shared.CreateSessionProvider(sess)
bootWks(c, prov)
bootWeb(prov)
<-shared.GetInterruptChan()
l.Debugln("interrupt signal received!")
prov.Provide().Close(false)
cancel()
time.Sleep(time.Second)
shared.StopBus()
l.Debugln("done")
}
func bootWks(ctx context.Context, glob mongo.SessionProvider) {
prov := shared.CreateCopySessionProvider(glob)
exec := shared.CreateOperationExecutor(prov)
rfac := shared.CreateRepositoryFactory(exec)
cfac := shared.CreateContextFactory(prov)
sfac := shared.CreateServiceFactory(rfac)
boot(&process.Module{ContextFactory: cfac, ServiceFactory: sfac})
shared.StartBus(ctx, shared.GetNameOrDefault("mono"), shared.CreateLogger("[..BUS..] "))
}
func bootWeb(glob mongo.SessionProvider) {
prov := shared.CreateCopySessionProvider(glob)
cfac := shared.CreateContextFactory(prov)
m := shared.ConfigureMux(cfac)
exec := shared.CreateOperationExecutor(prov)
rfac := shared.CreateRepositoryFactory(exec)
sfac := shared.CreateServiceFactory(rfac)
m.Route("/v1/api", func(r chi.Router) {
commandRouter := chi.NewRouter()
notifyRouter := chi.NewRouter()
boardRouter := chi.NewRouter()
boot(&command.Module{Router: commandRouter})
boot(¬ify.Module{Router: notifyRouter})
boot(&query.Module{BoardRouter: boardRouter, LaneRouter: boardRouter, CardRouter: boardRouter, ServiceFactory: sfac})
boot(&update.Module{BoardRouter: boardRouter, LaneRouter: boardRouter, CardRouter: boardRouter, ServiceFactory: sfac})
r.Mount("/command", commandRouter)
r.Mount("/notify", notifyRouter)
r.Mount("/board", boardRouter)
})
shared.StartMux(m, shared.GetPortOrDefault(3001), shared.CreateLogger("[..MUX..] "))
}
func boot(b interface{ Boot() }) {
b.Boot()
}