Main project #1

Merged
raul merged 33 commits from testing into main 2024-06-14 07:49:34 +02:00
1 changed files with 18 additions and 4 deletions
Showing only changes of commit 7d5c8a26aa - Show all commits

View File

@ -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) {