Created
June 21, 2016 04:21
-
-
Save narenaryan/a2ea9dfa5c8c8f0addb350faa8dcc7c2 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 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