36 lines
643 B
Go
36 lines
643 B
Go
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()
|
|
viper.WatchConfig()
|
|
if err != nil {
|
|
panic("")
|
|
}
|
|
}
|