Main project #1
|
@ -28,7 +28,7 @@ func server() {
|
||||||
LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html")
|
LoadHTMLFromEmbedFS(r, templatesFolder, "templates/*.html")
|
||||||
r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder))
|
r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder))
|
||||||
|
|
||||||
r.GET("/", autoDetectProvince)
|
r.GET("/", chooseProvince)
|
||||||
r.GET("/:local", returnProvince)
|
r.GET("/:local", returnProvince)
|
||||||
r.GET("/api/:localidad", returnAPIWeather)
|
r.GET("/api/:localidad", returnAPIWeather)
|
||||||
r.GET("/api/:localidad/:dia", returnAPIWeather)
|
r.GET("/api/:localidad/:dia", returnAPIWeather)
|
||||||
|
@ -36,16 +36,13 @@ func server() {
|
||||||
r.Run(":" + listenPort)
|
r.Run(":" + listenPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func autoDetectProvince(c *gin.Context) {
|
func chooseProvince(c *gin.Context) {
|
||||||
// c.HTML(http.StatusOK, "templates/index.html", gin.H{
|
c.HTML(http.StatusOK, "templates/redirect.html", gin.H{
|
||||||
// "title": "Hello world!",
|
"Localidades": localidades,
|
||||||
// })
|
})
|
||||||
|
|
||||||
// TODO: Try to autodetect the province of the IP and show the correct corresponding weather
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func returnProvince(c *gin.Context) {
|
func returnProvince(c *gin.Context) {
|
||||||
// TODO: Return prettified HTML representation of the weather based on url parameter
|
|
||||||
localidad := c.Param("local")
|
localidad := c.Param("local")
|
||||||
if isAv := localityIsAvailable(localidad); isAv != true {
|
if isAv := localityIsAvailable(localidad); isAv != true {
|
||||||
c.String(http.StatusNotFound, "The locality doesn't exist or is currently not supported, sorry\n")
|
c.String(http.StatusNotFound, "The locality doesn't exist or is currently not supported, sorry\n")
|
||||||
|
@ -56,7 +53,6 @@ func returnProvince(c *gin.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Sprint(err)
|
e := fmt.Sprint(err)
|
||||||
c.String(http.StatusInternalServerError, e)
|
c.String(http.StatusInternalServerError, e)
|
||||||
//c.String(500, jsonData)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,22 +13,22 @@
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<b>
|
<b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li class="hor">
|
||||||
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">Source code</a></p>
|
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">Source code</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="hor">
|
||||||
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">API Docs</a></p>
|
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">API Docs</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="hor">
|
||||||
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">But why though?</a></p>
|
<p><a href="https://git.bulgariu.xyz/raul/aemet" target="_blank">But why though?</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="hor">
|
||||||
<p>
|
<p>
|
||||||
<select
|
<select class="optionCap"
|
||||||
onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
|
onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
|
||||||
<option value="">Select...</option>
|
<option value="">Select...</option>
|
||||||
{{ range $key, $value := .Localidades }}
|
{{ range $key, $value := .Localidades }}
|
||||||
<option value="{{ $key }}">{{ $key }}</option>
|
<option value="{{ $key }}" class="optionCap">{{ $key }}</option>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>AEMET Client</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link href="style.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div id="main">
|
||||||
|
<b>
|
||||||
|
<ul>
|
||||||
|
{{ range $key, $value := .Localidades }}
|
||||||
|
<li>
|
||||||
|
<p><a href="{{ $key }}" class="optionCap">{{ $key }}</a></p>
|
||||||
|
</li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
</b>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -9,6 +9,10 @@ table {
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.optionCap {
|
||||||
|
text-transform: capitalize;
|
||||||
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
@ -17,11 +21,12 @@ ul {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
li {
|
li.hor {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
table * {
|
table * {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue