-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (55 loc) · 1.1 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
package main
import (
"os"
"strconv"
"telepushx/common"
"telepushx/model"
"telepushx/router"
"telepushx/task"
"time"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load(".env")
if err != nil {
common.FatalLog(err)
}
common.Init()
common.SetupDailyRotateLog()
common.SysLog("TelepushX " + common.Version + " started")
if os.Getenv("GIN_MODE") != "debug" {
gin.SetMode(gin.ReleaseMode)
}
// Connect to the database
err = model.InitDB()
if err != nil {
common.FatalLog(err)
}
defer func() {
err := model.CloseDB()
if err != nil {
common.FatalLog(err)
}
}()
// Initialize Redis
err = common.InitRedisClient()
if err != nil {
common.FatalLog(err)
}
// 调用定时任务
nextMinute := time.Now().Truncate(time.Minute).Add(time.Minute)
waitDuration := time.Until(nextMinute)
time.Sleep(waitDuration)
task.StartPushChecker()
server := gin.Default()
router.SetRouter(server)
var port = os.Getenv("PORT")
if port == "" {
port = strconv.Itoa(*common.Port)
}
err = server.Run(":" + port)
if err != nil {
common.FatalLog(err)
}
}