I want to change my current function to return empty JSON list, currently it returns nil
.
This is my current code:
func (s *Service) pro
Another way to handle this is to check if the slice is nil and initialize it:
projects = ps
if projects == nil {
projects = make([]*models.Project, 0)
}
This can be tedious if you have several structs and structs with arrays. To handle those, you can create custom marshalers or dynamically inspect fields.
Source: Arrays and JSON in Go