package main import ( "expenses/common" "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) } /*数据库初始化*/ _, err = common.InitDB(conf.DataSource) if err != nil { common.Log.Printf("数据库初始化失败!") os.Exit(-2) } /*Gin初始化*/ //gin.SetMode(gin.ReleaseMode) r := gin.Default() r = router.CollectRoute(r) port := 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) } }