Main project #1
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue