Skip to content

Instantly share code, notes, and snippets.

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

  • Save narenaryan/15e862ab38cf04145cf5a2b3bed49157 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/15e862ab38cf04145cf5a2b3bed49157 to your computer and use it in GitHub Desktop.
// 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