-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
54 lines (44 loc) · 1.08 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
/*
* @Author: NyanCatda
* @Date: 2021-12-05 22:27:13
* @LastEditTime: 2022-09-21 12:18:03
* @LastEditors: NyanCatda
* @Description:
* @FilePath: \MCBE-Server-Motd\main.go
*/
package main
import (
"flag"
"io/ioutil"
"strconv"
"github.com/gin-gonic/gin"
"github.com/nyancatda/AyaLog"
"github.com/nyancatda/AyaLog/ModLog/GinLog"
"github.com/nyancatda/AyaLog/TimedTask"
)
func main() {
RunPort := flag.Int("port", 8080, "指定运行端口")
DeBug := flag.Bool("debug", false, "是否开启调试模式")
flag.Parse()
// 设置日志参数
if !*DeBug {
AyaLog.LogLevel = AyaLog.INFO
}
// 启用日志压缩与清理任务
go TimedTask.Start()
// 关闭Gin默认的日志输出
if !*DeBug {
gin.DefaultWriter = ioutil.Discard
}
// 初始化Gin
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
// 注册日志中间件
r.Use((GinLog.GinLog()))
// 注册路由
SetupRouter(r)
AyaLog.Info("System", "程序启动完成!正在监听端口:"+strconv.Itoa(*RunPort))
if err := r.Run(":" + strconv.Itoa(*RunPort)); err != nil {
AyaLog.Error("System", err)
}
}