Skip to content

Commit

Permalink
Cleanup: only pass non-empty filters to device list API
Browse files Browse the repository at this point in the history
This shortens the URL, making it easier to debug.

Signed-off-by: Volodymyr Khoroz <[email protected]>
  • Loading branch information
vkhoroz committed Apr 19, 2024
1 parent 52832b0 commit 2194b0a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions client/foundries.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,16 @@ func (a *Api) DeviceList(filterBy map[string]string, sortBy string, page, limit
url := a.serverUrl + "/ota/devices/?"
query := netUrl.Values{}
for key, val := range filterBy {
query.Set(key, val)
if len(val) > 0 {
query.Set(key, val)
}
}
if len(sortBy) > 0 {
query.Set("sortby", sortBy)
}
if page > 1 {
query.Set("page", strconv.FormatUint(page, 10))
}
query.Set("sortby", sortBy)
query.Set("page", strconv.FormatUint(page, 10))
query.Set("limit", strconv.FormatUint(limit, 10))
url += query.Encode()
logrus.Debugf("DeviceList with url: %s", url)
Expand Down

0 comments on commit 2194b0a

Please sign in to comment.