Created
June 21, 2016 04:06
-
-
Save narenaryan/15e862ab38cf04145cf5a2b3bed49157 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
| // GET a person detail | |
| router.GET("/person/:id", func(c *gin.Context) { | |
| var ( | |
| person Person | |
| result gin.H | |
| ) | |
| id := c.Param("id") | |
| row := db.QueryRow("select id, first_name, last_name from person where id = ?;", id) | |
| err = row.Scan(&person.Id, &person.First_Name, &person.Last_Name) | |
| if err != nil { | |
| // If no results send null | |
| result = gin.H{ | |
| "result": nil, | |
| "count": 0, | |
| } | |
| } else { | |
| result = gin.H{ | |
| "result": person, | |
| "count": 1, | |
| } | |
| } | |
| c.JSON(http.StatusOK, result) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment