-
Notifications
You must be signed in to change notification settings - Fork 258
/
main.go
78 lines (71 loc) · 1.77 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
package main
import (
"context"
"go.uber.org/fx"
"github.com/go-sonic/sonic/cache"
"github.com/go-sonic/sonic/config"
"github.com/go-sonic/sonic/dal"
"github.com/go-sonic/sonic/event"
"github.com/go-sonic/sonic/event/listener"
"github.com/go-sonic/sonic/handler"
"github.com/go-sonic/sonic/handler/middleware"
"github.com/go-sonic/sonic/injection"
"github.com/go-sonic/sonic/log"
"github.com/go-sonic/sonic/template"
"github.com/go-sonic/sonic/template/extension"
)
var eventBus event.Bus
func main() {
app := InitApp()
if err := app.Start(context.Background()); err != nil {
panic(err)
}
eventBus.Publish(context.Background(), &event.StartEvent{})
<-app.Done()
}
func InitApp() *fx.App {
options := injection.GetOptions()
options = append(options,
fx.NopLogger,
fx.Provide(
log.NewLogger,
log.NewGormLogger,
event.NewSyncEventBus,
dal.NewGormDB,
cache.NewCache,
config.NewConfig,
handler.NewServer,
template.NewTemplate,
middleware.NewAuthMiddleware,
middleware.NewGinLoggerMiddleware,
middleware.NewRecoveryMiddleware,
middleware.NewInstallRedirectMiddleware,
),
fx.Populate(&dal.DB),
fx.Populate(&eventBus),
fx.Invoke(
listener.NewStartListener,
listener.NewTemplateConfigListener,
listener.NewLogEventListener,
listener.NewPostUpdateListener,
listener.NewCommentListener,
extension.RegisterCategoryFunc,
extension.RegisterCommentFunc,
extension.RegisterTagFunc,
extension.RegisterMenuFunc,
extension.RegisterPhotoFunc,
extension.RegisterLinkFunc,
extension.RegisterToolFunc,
extension.RegisterPaginationFunc,
extension.RegisterPostFunc,
extension.RegisterStatisticFunc,
func(s *handler.Server) {
s.RegisterRouters()
},
),
)
app := fx.New(
options...,
)
return app
}