-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements pagination support for GetAll style endpoints (#429)
Signed-off-by: Alex Creasy <[email protected]>
- Loading branch information
1 parent
50bf73e
commit 9cc09d9
Showing
10 changed files
with
171 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package data | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
func FilterPageValues(values url.Values) url.Values { | ||
result := url.Values{} | ||
|
||
if v := values.Get("pageSize"); v != "" { | ||
result.Set("pageSize", v) | ||
} | ||
if v := values.Get("orderBy"); v != "" { | ||
result.Set("orderBy", v) | ||
} | ||
if v := values.Get("sortOrder"); v != "" { | ||
result.Set("sortOrder", v) | ||
} | ||
if v := values.Get("nextPageToken"); v != "" { | ||
result.Set("nextPageToken", v) | ||
} | ||
|
||
return result | ||
} | ||
|
||
func UrlWithParams(url string, values url.Values) string { | ||
queryString := values.Encode() | ||
if queryString == "" { | ||
return url | ||
} | ||
return fmt.Sprintf("%s?%s", url, queryString) | ||
} | ||
|
||
func UrlWithPageParams(url string, values url.Values) string { | ||
pageValues := FilterPageValues(values) | ||
return UrlWithParams(url, pageValues) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.