Setting Get metadata method to return both an interface as well as an error to remove panic.

This commit is contained in:
Nick Gerakines
2014-07-03 15:17:24 -04:00
parent 5eb0e10a78
commit 108bfb4470
2 changed files with 8 additions and 13 deletions

View File

@ -38,14 +38,14 @@ func main() {
}))
authorized.POST("admin", func(c *gin.Context) {
user := c.Get("user").(string)
user, _ := c.Get("user")
// Parse JSON
var json struct {
Value string `json:"value" binding:"required"`
}
if c.EnsureBody(&json) {
DB[user] = json.Value
DB[user.(string)] = json.Value
c.JSON(200, gin.H{"status": "ok"})
}
})