I have a query which casts into a struct. But when the query returns no results the response is null
- how do I get this to be an empty array []
?
_, err := dbmap.Select(&response.DevTeam, "SELECT * FROM DevTeam WHERE app_id = ? LIMIT ? OFFSET ?", a_id, limit, offset)
Response when no results:
{
"data": null,
"meta": "success"
}
Desired response when no results:
{
"data": [],
"meta": "success"
}
Still getting null - my struct setup is:
type HttpResonse struct {
DevTeam []DevTeam `json:"data"`
}
I am using response.DevTeam = []models.DevTeam{}
as suggested below but still getting null
.
Response section:
s.Count = int64(len(response.DevTeam))
c.JSON(httpcode, gin.H{"meta": s, "data": response.DevTeam})