-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
39 lines (34 loc) · 823 Bytes
/
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
package main
import (
"gapp/models"
"gapp/routers"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/lestrrat/go-file-rotatelogs"
"log"
"time"
)
func main() {
godotenv.Load(".env")
// 设置分割日志
//logWriterFormat := "var/log/gin.%Y%m%d.%H%M.log"
logWriterFormat := "var/log/gin.%Y%m%d.log"
logWriter, err := rotatelogs.New(
logWriterFormat,
rotatelogs.WithLinkName("var/log/access_log.log"),
rotatelogs.WithMaxAge(24 * time.Hour),
rotatelogs.WithRotationTime(time.Hour),
)
if err != nil {
log.Printf("failed to create rotatelogs: %s", err)
return
}
gin.DefaultWriter = logWriter
engine := gin.Default()
engine.LoadHTMLGlob("resources/themes/***/***/*")
// 初始化路由
routers.InitRouter(engine)
// 初始化模型
models.ConnectDB()
engine.Run(":8080")
}