Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save narenaryan/a2ea9dfa5c8c8f0addb350faa8dcc7c2 to your computer and use it in GitHub Desktop.
// GET all persons
router.GET("/persons", func(c *gin.Context) {
var (
person Person
persons []Person
)
rows, err := db.Query("select id, first_name, last_name from person;")
if err != nil {
fmt.Print(err.Error())
}
for rows.Next() {
err = rows.Scan(&person.Id, &person.First_Name, &person.Last_Name)
persons = append(persons, person)
if err != nil {
fmt.Print(err.Error())
}
}
defer rows.Close()
c.JSON(http.StatusOK, gin.H{
"result": persons,
"count": len(persons),
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment