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 package cmd
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -18,13 +19,26 @@ var (
} }
) )
//go:embed templates/*
var templatesFolder embed.FS
func server() { func server() {
//gin.SetMode(gin.ReleaseMode) //gin.SetMode(gin.ReleaseMode)
router := gin.Default() r := gin.Default()
router.GET("/api/:localidad", returnWeather) LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html")
router.GET("/api/:localidad/:dia", returnWeather) 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) 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) { func returnWeather(c *gin.Context) {