aemet/cmd/serverFunc.go

32 lines
596 B
Go
Raw Normal View History

2024-05-08 09:08:36 +02:00
package cmd
import (
"fmt"
2024-05-08 09:16:05 +02:00
"net/http"
2024-05-08 09:08:36 +02:00
"github.com/gin-gonic/gin"
)
var (
listenPort string = "1302"
)
func server() {
2024-05-08 09:16:05 +02:00
router := gin.Default()
router.GET("/api/valencia", returnWeather)
fmt.Printf("Listening on port %v...\n", listenPort)
router.Run("localhost:" + listenPort)
}
func returnWeather(c *gin.Context) {
jsonData := getJSON()
c.IndentedJSON(http.StatusOK, jsonData)
//textBytes := []byte(jsonData)
// aemetRequest := root{}
// err := json.Unmarshal(textBytes, &aemetRequest)
// if err != nil {
// log.Fatalf("Error occurred unmarshalling data: %v\n", err)
// }
2024-05-08 09:08:36 +02:00
}