Properly render JSON

This commit is contained in:
raul 2024-05-08 09:29:58 +02:00
parent 8e04491386
commit 6354a824f9
1 changed files with 10 additions and 9 deletions

View File

@ -1,10 +1,11 @@
package cmd
import (
"encoding/json"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"log"
"net/http"
)
var (
@ -20,12 +21,12 @@ func server() {
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)
// }
textBytes := []byte(jsonData)
aemetRequest := root{}
err := json.Unmarshal(textBytes, &aemetRequest)
if err != nil {
log.Fatalf("Error occurred unmarshalling data: %v\n", err)
}
c.IndentedJSON(http.StatusOK, aemetRequest)
}