Skip to content

Commit

Permalink
Change empty search response from null to [] (#111)
Browse files Browse the repository at this point in the history
So far if the filter on the `/search` endpoint returned no results, it returned `null`. To still have an array type, it should return `[]` instead. This changes the behaviour.
  • Loading branch information
ruflin authored Sep 23, 2019
1 parent 1a5841f commit 2c78994
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Change empty /search API output from `null` to `[]`.

### Deprecated

### Removed
Expand Down
5 changes: 5 additions & 0 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,10 @@ func getPackageOutput(packagesList map[string]map[string]util.Package) ([]byte,
output = append(output, data)
}

// Instead of return `null` in case of an empty array, return []
if len(output) == 0 {
return []byte("[]"), nil
}

return json.MarshalIndent(output, "", " ")
}

0 comments on commit 2c78994

Please sign in to comment.