-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (50 loc) · 1.22 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
package main
import (
"context"
"errors"
"log"
"github.com/airdb/scout/bootstrap"
cachemod "github.com/airdb/scout/modules/cache"
discordmod "github.com/airdb/scout/modules/discord"
openaimod "github.com/airdb/scout/modules/openai"
telemetrymod "github.com/airdb/scout/modules/telemetry"
wecommod "github.com/airdb/scout/modules/wecom"
"github.com/airdb/scout/pkg/lokikit"
"github.com/joho/godotenv"
"go.uber.org/fx"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
type invokeDeps struct {
fx.In
LokiWriter *lokikit.LokiWriter
Discord *bootstrap.Discord
Wecom *bootstrap.Wecom
}
app := fx.New(
telemetrymod.FxOptions(),
cachemod.FxOptions(),
openaimod.FxOptions(),
discordmod.FxOptions(),
wecommod.FxOptions(),
bootstrap.FxOptions(),
fx.Invoke(func(lc fx.Lifecycle, deps invokeDeps) {
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
go deps.Discord.Start()
go deps.Wecom.Start()
log.Println("Press Ctrl+C to exit")
return nil
},
OnStop: func(ctx context.Context) error {
deps.LokiWriter.Shutdown()
return errors.Join(deps.Discord.Stop(), deps.Wecom.Stop())
},
})
}),
)
app.Run()
}