-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
60 lines (47 loc) · 1.31 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
package main
import (
"github.com/geeklubcn/feishu-bitable-db/db"
lark "github.com/larksuite/oapi-sdk-go/v3"
larkcore "github.com/larksuite/oapi-sdk-go/v3/core"
"github.com/wangyuheng/richman/internal/infrastructure/database"
"log"
"net/http"
"time"
ginzap "github.com/gin-contrib/zap"
"go.uber.org/zap"
"github.com/gin-contrib/pprof"
"github.com/gin-contrib/requestid"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/wangyuheng/richman/config"
)
func main() {
cfg := config.Load()
logrus.SetLevel(cfg.LogLevel)
logrus.Debugf("load config. %+v", cfg)
bdb, err := db.NewDB(cfg.DbAppId, cfg.DbAppSecret)
if err != nil {
panic(err)
}
larkCli := lark.NewClient(cfg.DbAppId, cfg.DbAppSecret,
lark.WithLogLevel(larkcore.LogLevelDebug),
lark.WithReqTimeout(100*time.Second),
lark.WithHttpClient(http.DefaultClient))
auditLogger := database.NewAuditLogService(cfg, bdb)
r, err := InitializeEngine(cfg, bdb, larkCli, auditLogger)
if err != nil {
panic(err)
}
t, _ := InitializeTask(cfg, bdb, larkCli)
t.Start()
pprof.Register(r)
r.Use(requestid.New())
logger, _ := zap.NewProduction()
r.Use(ginzap.Ginzap(logger, time.RFC3339, true))
r.Use(ginzap.RecoveryWithZap(logger, true))
r.Use(gin.Logger())
r.Use(gin.Recovery())
if err = r.Run(); err != nil {
log.Fatal(err)
}
}