package main import ( "os" "github.com/gin-gonic/gin" "github.com/spf13/viper" "github.com/zggsong/gin-vue-demo/common" "github.com/zggsong/gin-vue-demo/router" ) func init() { workDir, _ := os.Getwd() viper.SetConfigName("application") viper.SetConfigType("yml") viper.AddConfigPath(workDir + "/config") err := viper.ReadInConfig() if err != nil { panic("读取配置文件失败, error=" + err.Error()) } } func main() { common.InitDB() r := gin.Default() r = router.CollectRoute(r) port := viper.GetString("server.port") if port != "" { panic(r.Run(":" + port)) } panic(r.Run(":8080")) }