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

Unified Diff: milo/appengine/settings/settings.go

Issue 2328733002: Milo: Add ?limit= support to builders (Closed)
Patch Set: Rebase Created 4 years, 2 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
Index: milo/appengine/settings/settings.go
diff --git a/milo/appengine/settings/settings.go b/milo/appengine/settings/settings.go
index 82148f8869a3ef93e69f2f92d3cdd43352368049..ae5e30aa2b163858d7cdd22d6af5ba3cc662416a 100644
--- a/milo/appengine/settings/settings.go
+++ b/milo/appengine/settings/settings.go
@@ -9,10 +9,12 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "strconv"
ds "github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/milo/api/resp"
"github.com/luci/luci-go/milo/appengine/model"
+ "github.com/luci/luci-go/milo/common/miloerror"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/auth/identity"
"github.com/luci/luci-go/server/auth/xsrf"
@@ -149,3 +151,26 @@ func getSettings(c context.Context, r *http.Request) (*resp.Settings, error) {
return result, nil
}
+
+// GetLimit extracts the "limit" http param from the request, or returns "-1"
+// implying no limit was specified.
+func GetLimit(r *http.Request) (int, error) {
nodir 2016/10/28 07:17:54 why this is in settings package? what does limit q
hinoka 2016/10/28 19:47:30 Technically nothing, i'm using the settings packag
nodir 2016/10/28 19:52:51 Perhaps this needs some refactoring. Go does not e
hinoka 2016/10/28 19:53:42 The alternative would be copypasta code...?
+ sLimit := r.FormValue("limit")
nodir 2016/10/28 07:17:54 can you also fall back to "numBuilds"? this is wha
hinoka 2016/10/28 19:47:30 Done.
+ if sLimit == "" {
+ return -1, nil
+ }
+ limit, err := strconv.Atoi(sLimit)
+ if err != nil {
+ return -1, &miloerror.Error{
+ Message: fmt.Sprintf("limit parameter value %q is not a number: %s", sLimit, err),
+ Code: http.StatusBadRequest,
+ }
+ }
+ if limit < 0 {
+ return -1, &miloerror.Error{
+ Message: fmt.Sprintf("limit parameter value %q is less than 0", sLimit),
+ Code: http.StatusBadRequest,
+ }
+ }
+ return limit, nil
+}

Powered by Google App Engine
This is Rietveld 408576698