-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
74 lines (62 loc) · 1.62 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
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/gnasnik/titan-explorer/api"
"github.com/gnasnik/titan-explorer/config"
"github.com/gnasnik/titan-explorer/core/dao"
"github.com/gnasnik/titan-explorer/core/opasynq"
"github.com/gnasnik/titan-explorer/core/oplog"
"github.com/gnasnik/titan-explorer/core/oprds"
"github.com/gnasnik/titan-explorer/job"
"github.com/gnasnik/titan-explorer/pkg/oss"
logging "github.com/ipfs/go-log/v2"
"github.com/spf13/viper"
)
// @title Titan Explorer API
// @version 1.0
// @description This is titan explorer backend server.
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
func main() {
OsSignal := make(chan os.Signal, 1)
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.SetConfigType("toml")
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("reading config file: %v\n", err)
}
var cfg config.Config
if err := viper.Unmarshal(&cfg); err != nil {
log.Fatalf("unmarshaling config file: %v\n", err)
}
config.Cfg = cfg
if cfg.Mode == "debug" {
logging.SetDebugLogging()
}
if err := dao.Init(&cfg); err != nil {
log.Fatalf("initital: %v\n", err)
}
if err := oss.InitFromCfg(cfg.Oss); err != nil {
log.Fatalf("init oss: %v\n", err)
}
oplog.Subscribe(context.Background())
oprds.Init()
opasynq.Init()
srv, err := api.NewServer(cfg)
if err != nil {
log.Fatalf("create api server: %v\n", err)
}
go srv.Run()
job.SyncShedulersAsset()
go job.StartAsynqServer()
signal.Notify(OsSignal, syscall.SIGINT, syscall.SIGTERM)
_ = <-OsSignal
srv.Close()
fmt.Printf("Exiting received OsSignal\n")
}