Add basic server functionality
This commit is contained in:
parent
08fb32b4b2
commit
8e04491386
|
@ -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()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue