37 lines
803 B
Go
37 lines
803 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"go_api_tmpl/core"
|
|
"go_api_tmpl/global"
|
|
"go_api_tmpl/handle"
|
|
"go_api_tmpl/initialization"
|
|
"go_api_tmpl/middleware"
|
|
"go_api_tmpl/route"
|
|
)
|
|
|
|
func main() {
|
|
// 初始化日志工具
|
|
global.InitLogger()
|
|
// 初始化数据库连接
|
|
global.InitMySQLClient()
|
|
// 初始化相关组件
|
|
initialization.Init()
|
|
|
|
// 初始化Gin
|
|
//app := gin.New()
|
|
//app.Use(middleware.ZapLogger(), gin.Recovery())
|
|
app := gin.Default()
|
|
// 定义全局异常处理
|
|
app.NoRoute(core.NotFoundErrorHandler())
|
|
// 保存接口访问记录
|
|
app.Use(middleware.SaveRequestLog(), middleware.CheckDeviceId())
|
|
// 初始化路由
|
|
route.InitRoute(app)
|
|
// 路由初始化完毕,入库所有接口
|
|
handle.SaveAllRoute(app.Routes())
|
|
|
|
// 启动项目
|
|
_ = app.Run(":8888")
|
|
}
|