From 8e04491386021e172468c3787e46ccbeac315997 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 8 May 2024 09:16:05 +0200 Subject: [PATCH] Add basic server functionality --- cmd/server.go | 1 + cmd/serverFunc.go | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 98d74cf..0c7ab27 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -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() }, } diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index f2c3b3f..fafda14 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -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) + // } + }