func (env Env) NewKnot(c *gin.Context) { var new models.Knot err := c.BindJSON(&new) if err == nil && new.Validate() { err := new.Insert(env.db) if err != nil { c.JSON(http.StatusInternalServerError, nil) } else { c.JSON(http.StatusOK, gin.H{ "status": "posted", "title": new.Title, }) } } else { sendBadRequest(c, fmt.Errorf("invalid_data")) } }