-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (50 loc) · 1.16 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
/**
* @projectName: GinCoBlog
* @package: GinCoBlog
* @className: main
* @author: 张杰
* @description: TODO
* @date: 2023/10/4 9:23
* @version: 1.0
*/
package main
// 引入相关依赖
import (
"GinCoBlog/config"
"GinCoBlog/middleware"
routes "GinCoBlog/router"
"GinCoBlog/service"
"fmt"
"log"
"net/http"
genic "github.com/gin-gonic/gin"
)
// 项目主方法
func main() {
// 获取项目路由
router := genic.New()
// 挂载中间件
router.Use(genic.Logger(), genic.Recovery(), middleware.CorsMiddleware(), middleware.LoggerToFile(), middleware.JwtVerifyMiddle())
// 加载代理中间件
err := router.SetTrustedProxies([]string{"192.168.1.0/24"})
if err != nil {
fmt.Println("代理失败!")
return
}
// 验证数据表是否存在
service.VerDataBase()
// 编写项目基础接口
router.GET("/", func(c *genic.Context) {
c.JSON(http.StatusOK, "HelloWorld!")
})
// 调用项目主路由
routes.SetupRouterGroup(router.Group("/api"))
// 开启端口监听
err = router.Run(":" + config.Default().Port)
// 开启监听失败
if err != nil {
// 写入日志
log.Fatalln("项目启动失败!")
return
}
}