-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 1.09 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
package main
import (
"context"
"github.com/caarlos0/env/v10"
"log/slog"
"mosaic/api"
"mosaic/engine"
"mosaic/mosaicdb"
"mosaic/storage"
"mosaic/types"
"mosaic/utils"
"os"
"os/signal"
"syscall"
)
func main() {
slog.Info("MOSAIC")
appCfg := &types.AppConfig{}
utils.PanicIfErr(env.Parse(appCfg))
slog.Info("Config ok.")
sigs := make(chan os.Signal, 1) // we need to reserve to buffer size 1, so the notifier are not blocked
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
cancelCtx := setup(appCfg)
<-sigs
cancelCtx()
slog.Info("exit from main()")
}
func setup(appCfg *types.AppConfig) context.CancelFunc {
database := mosaicdb.NewDatabase(appCfg.DbPath)
storage := storage.NewStorage()
appCtx, cancel := context.WithCancel(context.Background())
engine, err := engine.NewEngine(appCtx, appCfg.FilesTempFolder, database, storage, int(appCfg.FileUploadWorkersCount))
if err != nil {
panic(err)
}
// setup http API
httpApi := api.NewHttpApi(appCfg.ApiHttpAddress, appCfg.ApiHttpPort, engine)
go func() {
// block main thread
httpApi.SetupHttpServer()
}()
return cancel
}