Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
controller: Render an empty JSON array when crud lists are empty
Browse files Browse the repository at this point in the history
Signed-off-by: Lewis Marshall <lewis@lmars.net>
  • Loading branch information
lmars committed Apr 24, 2014
1 parent 0e8b263 commit d0ebcc0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func crud(resource string, example interface{}, repo Repository, r martini.Route
r.JSON(500, struct{}{})
return
}
// render an empty JSON array (rather than null) if list is nil
if list == nil {
list = []struct{}{}
}
r.JSON(200, list)
})

Expand Down

0 comments on commit d0ebcc0

Please sign in to comment.