gorm db.find(&users) to json with gin in golang

7.2k Views Asked by At

This is my GET Method the problem is that all i get in the json is one user instead there are 3 users in my database.

func GetUsers(c *gin.Context) {

var users = db.Find(&models.Person{})
c.JSON(200, users)
}
1

There are 1 best solutions below

0
On BEST ANSWER

Try this:

func GetUsers(c *gin.Context) {
 users := []models.Person{}
 db.Find(&users)
 c.JSON(200, &users)
}