Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1407)

Unified Diff: milo/frontend/middleware.go

Issue 2976393002: Milo: Fix ?limit= param (Closed)
Patch Set: review Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/buildsource/builder.go ('k') | milo/frontend/view_builder.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/frontend/middleware.go
diff --git a/milo/frontend/middleware.go b/milo/frontend/middleware.go
index 7c750c2d03bcdbd056f48ca5816f69b6b68625d2..b728c2296285f8e33e1cd47a5a8894d3740525a3 100644
--- a/milo/frontend/middleware.go
+++ b/milo/frontend/middleware.go
@@ -225,26 +225,23 @@ func shortHash(s string) string {
}
// GetLimit extracts the "limit", "numbuilds", or "num_builds" http param from
-// the request, or returns "-1" implying no limit was specified.
-func GetLimit(r *http.Request) (int, error) {
+// the request, or returns def implying no limit was specified.
+func GetLimit(r *http.Request, def int) int {
sLimit := r.FormValue("limit")
if sLimit == "" {
sLimit = r.FormValue("numbuilds")
if sLimit == "" {
sLimit = r.FormValue("num_builds")
if sLimit == "" {
- return -1, nil
+ return def
}
}
}
limit, err := strconv.Atoi(sLimit)
- if err != nil {
- return -1, fmt.Errorf("limit parameter value %q is not a number: %s", sLimit, err)
+ if err != nil || limit < 0 {
+ return def
}
- if limit < 0 {
- return -1, fmt.Errorf("limit parameter value %q is less than 0", sLimit)
- }
- return limit, nil
+ return limit
}
// pagedURL returns a self URL with the given cursor and limit paging options.
@@ -252,13 +249,7 @@ func GetLimit(r *http.Request) (int, error) {
// both are unspecified, then limit is omitted.
func pagedURL(r *http.Request, limit int, cursor string) string {
if limit == 0 {
- var err error
- limit, err = GetLimit(r)
- if err != nil {
- // This should not happen because the handler should've already validated the
- // limit earlier in the process.
- panic(err)
- }
+ limit = GetLimit(r, -1)
if limit < 0 {
limit = 0
}
« no previous file with comments | « milo/buildsource/builder.go ('k') | milo/frontend/view_builder.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698