Skip to content

Commit

Permalink
uses ShouldBind instead of json
Browse files Browse the repository at this point in the history
  • Loading branch information
kneerunjun committed Mar 22, 2024
1 parent e1739a2 commit 9e95d35
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"io"
"net/http"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9e95d35

Please sign in to comment.