I am trying to write a rest endpoint using gin which should return status 200. I have coded it as well in the same way, but am getting status 400. My code is as follows:
router.POST("/parent", func(c *gin.Context) {
var parent PARENT
err := c.BindJSON(&parent)
con,err := sql.Open("mysql", "myuser:mypass@/mydb")
res,err := con.Exec(" insert into parent (username, mobile, email, password) values (?,?,?,?) ", parent.USERNAME, parent.MOBILE, parent.EMAIL, parent.PASSWORD)
id,err := res.LastInsertId()
if err != nil {
con.Close()
}
c.JSON(200, gin.H{"success" : 1, "userid" : id})
return
})
I am always getting this in gin logs:
[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 200
Any idea what am I missing. Thanks