package main import ( "expenses/common" "expenses/global" "expenses/router" "github.com/gin-gonic/gin" "os" ) func main() { /*日志初始化*/ common.Init() /*配置文件初始化*/ conf, err := common.ConfigInit() if err != nil { common.Log.Printf("加载配置文件失败!") os.Exit(-1) } /*数据库初始化*/ initDB, err := common.InitDB(conf.DataSource) if err != nil { common.Log.Printf("数据库初始化失败!") os.Exit(-2) } /*全局变量初始化*/ global.GLO_CONF = conf global.GLO_DB = initDB /*Gin初始化*/ //gin.SetMode(gin.ReleaseMode) r := gin.Default() r = router.CollectRoute(r) port := global.GLO_CONF.Server.Port 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) } }