You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
770 B

2 years ago
package main
import (
2 years ago
"expenses/common"
"expenses/router"
"github.com/gin-gonic/gin"
2 years ago
"os"
)
func main() {
/*日志初始化*/
2 years ago
common.Init()
2 years ago
/*配置文件初始化*/
2 years ago
conf, err := common.ConfigInit()
2 years ago
if err != nil {
2 years ago
common.Log.Printf("加载配置文件失败!")
2 years ago
os.Exit(-1)
}
/*数据库初始化*/
_, err = common.InitDB(conf.DataSource)
2 years ago
if err != nil {
2 years ago
common.Log.Printf("数据库初始化失败!")
2 years ago
os.Exit(-2)
}
2 years ago
/*Gin初始化*/
//gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r = router.CollectRoute(r)
port := conf.Server.Port
2 years ago
if port == "" {
port = "8080"
}
common.Log.Printf("启动服务,端口: %v", port)
if err := r.Run("127.0.0.1:" + port); err != nil {
common.Log.Printf("启动服务失败!")
os.Exit(-3)
}
2 years ago
}