diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 26c739d..6777b93 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -1,6 +1,7 @@ package cmd import ( + "embed" "encoding/json" "fmt" "net/http" @@ -18,13 +19,26 @@ var ( } ) +//go:embed templates/* +var templatesFolder embed.FS + func server() { //gin.SetMode(gin.ReleaseMode) - router := gin.Default() - router.GET("/api/:localidad", returnWeather) - router.GET("/api/:localidad/:dia", returnWeather) + r := gin.Default() + LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html") + r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder)) + + r.GET("/", returnIndex) + r.GET("/api/:localidad", returnWeather) + r.GET("/api/:localidad/:dia", returnWeather) fmt.Printf("Listening on port %v...\n", listenPort) - router.Run(":" + listenPort) + r.Run(":" + listenPort) +} + +func returnIndex(c *gin.Context) { + c.HTML(http.StatusOK, "templates/index.html", gin.H{ + "title": "Hello world!", + }) } func returnWeather(c *gin.Context) {