Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Created June 21, 2016 04:24
Show Gist options
  • Select an option

  • Save narenaryan/574647c1c63ded647b2823f8addf078a to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/574647c1c63ded647b2823f8addf078a to your computer and use it in GitHub Desktop.
// POST new person details
router.POST("/person", func(c *gin.Context) {
var buffer bytes.Buffer
first_name := c.PostForm("first_name")
last_name := c.PostForm("last_name")
stmt, err := db.Prepare("insert into person (first_name, last_name) values(?,?);")
if err != nil {
fmt.Print(err.Error())
}
_, err = stmt.Exec(first_name, last_name)
if err != nil {
fmt.Print(err.Error())
}
// Fastest way to append strings
buffer.WriteString(first_name)
buffer.WriteString(" ")
buffer.WriteString(last_name)
defer stmt.Close()
name := buffer.String()
c.JSON(http.StatusOK, gin.H{
"message": fmt.Sprintf(" %s successfully created", name),
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment