2023-08-03 10:29:01 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gin-demo/route"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
InitConfig()
|
|
|
|
|
|
|
|
r := gin.Default()
|
|
|
|
r.LoadHTMLGlob("templates/*.html")
|
|
|
|
// r.StaticFS("/static", http.Dir("./static"))
|
|
|
|
r = route.CollectRoute(r)
|
|
|
|
port := viper.GetString("server.port")
|
|
|
|
if port != "" {
|
|
|
|
panic(r.Run(":" + port))
|
|
|
|
}
|
|
|
|
panic(r.Run()) // listen and serve on 0.0.0.0:8080
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitConfig() {
|
|
|
|
workDir, _ := os.Getwd()
|
|
|
|
viper.SetConfigName("application")
|
|
|
|
viper.SetConfigType("yml")
|
|
|
|
viper.AddConfigPath(workDir + "/config")
|
|
|
|
err := viper.ReadInConfig()
|
2023-11-07 11:05:36 +08:00
|
|
|
viper.WatchConfig()
|
2023-08-03 10:29:01 +08:00
|
|
|
if err != nil {
|
|
|
|
panic("")
|
|
|
|
}
|
|
|
|
}
|