-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
59 lines (53 loc) · 1.23 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
package main
/*
* @Author: xiaozuhui
* @Date: 2022-10-31 09:17:18
* @LastEditors: xiaozuhui
* @LastEditTime: 2022-12-22 10:19:45
* @Description:
*/
import (
"chatshock/configs"
"chatshock/middlewares"
"chatshock/websockets"
"flag"
"os"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func init() {
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05",
ForceQuote: true,
})
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
}
func main() {
var configVersion string
flag.StringVar(&configVersion, "c", "dev", "请输入配置版本(dev,product,)")
flag.Parse()
var r = gin.New()
r.Use(middlewares.AccessLog())
//r.Use(gin.Recovery())
r.Use(gin.CustomRecovery(func(c *gin.Context, err any) {
c.JSON(500, gin.H{"code": -1, "err_msg": err.(error).Error()})
c.Abort()
}))
InitConfig(configVersion)
InitDatabase()
InitRedis()
InitMinioClient()
InitRouters(r)
err := websockets.BroadCaster.ReLinkChatRooms()
if err != nil {
log.Fatal(errors.WithStack(err))
}
runHost := configs.Conf.AppConfig.AppHost + ":" + configs.Conf.AppConfig.AppPort
err = r.Run(runHost)
if err != nil {
log.Fatal(errors.WithStack(err))
}
}