Add basic server functionality

This commit is contained in:
raul 2024-05-08 09:16:05 +02:00
parent 08fb32b4b2
commit 8e04491386
2 changed files with 18 additions and 2 deletions

View File

@ -22,6 +22,7 @@ to quickly create a Cobra application.`,
if err := setServerParameters(cmd); err != nil {
log.Fatalf("Error happened trying to set parameters: %v\n", err)
}
server()
},
}

View File

@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
@ -11,6 +12,20 @@ var (
)
func server() {
router := gin.Default
getJSON()
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)
// }
}