gin: c.ShouldBindJSON undefined (type *gin.Context has no field or method ShouldBindJSON)
-
the err is as below: c.ShouldBindJSON undefined (type *gin.Context has no field or method ShouldBindJSON)
-
the code is as below:
func (this *CommonController) SetRepo(c *gin.Context) {
var json db_models.Repo
if err := c.ShouldBindJSON(&json); err == nil {
if json.ParentID == "manu" {
c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
} else {
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
}
} else {
c.JSON(http.StatusBadRequest, gin.H{"errorformat": err.Error()})
}
c.JSON(http.StatusOK, gin.H{
"RepoID": "1",
"RepoName": "capital",
})
}
-
i have imported
"gopkg.in/gin-gonic/gin.v1" -
how to fix this error?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (1 by maintainers)
I fixed this by using branch: master in dep, here’s my dep entry [[constraint]] name = “github.com/gin-gonic/gin” branch=“master”
This is a problem with this repo and the way dep works. Dep automatically pulls from the latest RELEASE 1.2.0 (commit d459835) in July 2017, not the latest master branch. Because this repo isn’t releasing minor versions like 1.2.1, we need to do what @vivekkartha suggested. I would recommend releasing more often for us dep users.
After some tinkering for some reason this line works:
works
doesnt work
@sidmutha Actually converting the project from glide to dep just works with the following specs: Gopkg.toml:
Gopkg.lock: