Using gorm
to connect db. Here get all the records:
func GetPeople(c *gin.Context) {
var people []Person
var count int
find_people := db.Find(&people)
find_people.Count(&count)
if err := find_people.Error; err != nil {
c.AbortWithStatus(404)
fmt.Println(err)
} else {
c.Header("X-Total-Count", &count)
c.JSON(200, people)
}
}
About count
, the c.Header("X-Total-Count", &count)
can't passed since this error:
cannot use &count (type *int) as type string in argument to c.Header
Have tried strconv.Itoa(&count)
, got another error:
cannot use &count (type *int) as type int in argument to strconv.Itoa
So how to convert integer to string in this case?