Created
June 21, 2016 04:24
-
-
Save narenaryan/574647c1c63ded647b2823f8addf078a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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