Properly render JSON
This commit is contained in:
parent
8e04491386
commit
6354a824f9
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue