From 9e95d358146878daa1c43dc1690dc484f380ad69 Mon Sep 17 00:00:00 2001 From: Niranjan Date: Fri, 22 Mar 2024 17:26:48 +0530 Subject: [PATCH] uses ShouldBind instead of json --- main.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 575961c..3d1f676 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,7 @@ package main import ( - "encoding/json" "fmt" - "io" "net/http" "github.com/gin-gonic/gin" @@ -57,15 +55,10 @@ func main() { api := r.Group("/api") api.Use(CORS).POST("/test", func(c *gin.Context) { fmt.Println("We have received hook notification..") - byt, err := io.ReadAll(c.Request.Body) - if err != nil { - fmt.Println("Error reading the request payload") - fmt.Println(err) - c.AbortWithStatus(http.StatusBadRequest) - return - } res := WebHkRelease{} - err = json.Unmarshal(byt, &res) + err := c.ShouldBind(&res) + defer c.Request.Body.Close() + if err != nil { fmt.Println("Error unmarshaling the payload") fmt.Println(err)