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.

34 lines
619 B

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"))
}