package cmd import ( "encoding/json" "fmt" "github.com/gin-gonic/gin" "log" "net/http" ) var ( listenPort string = "1302" ) func server() { router := gin.Default() router.GET("/api/valencia", returnWeather) fmt.Printf("Listening on port %v...\n", listenPort) router.Run(":" + listenPort) } func returnWeather(c *gin.Context) { jsonData := getJSON() 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) }