Init result slice to prevent /alerts returning `null`

When there are no alerts to return the api endpoint `/alerts` should
return:
```
{
  "status": "success",
  "data": []
}
```
instead of
```
{
  "status": "success",
  "data": null
}
```
This commit is contained in:
Max Leonard Inden 2017-05-02 11:23:56 +02:00
parent 02f14775e5
commit 96a28bbc36
No known key found for this signature in database
GPG Key ID: 5403C5464810BC26
1 changed files with 4 additions and 2 deletions

View File

@ -256,10 +256,12 @@ type APIAlert struct {
func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) {
var (
err error
res []*APIAlert
// Initialize result slice to prevent api returning `null` when there
// are no alerts present
res = []*APIAlert{}
matchers = []*labels.Matcher{}
)
matchers := []*labels.Matcher{}
if filter := r.FormValue("filter"); filter != "" {
matchers, err = parse.Matchers(filter)
if err != nil {