| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package settings |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "net/http" |
| 10 "strconv" |
| 11 |
| 12 "github.com/luci/luci-go/milo/common/miloerror" |
| 13 ) |
| 14 |
| 15 // GetLimit extracts the "limit", "numbuilds", or "num_builds" http param from |
| 16 // the request, or returns "-1" implying no limit was specified. |
| 17 func GetLimit(r *http.Request) (int, error) { |
| 18 sLimit := r.FormValue("limit") |
| 19 if sLimit == "" { |
| 20 sLimit = r.FormValue("numbuilds") |
| 21 if sLimit == "" { |
| 22 sLimit = r.FormValue("num_builds") |
| 23 if sLimit == "" { |
| 24 return -1, nil |
| 25 } |
| 26 } |
| 27 } |
| 28 limit, err := strconv.Atoi(sLimit) |
| 29 if err != nil { |
| 30 return -1, &miloerror.Error{ |
| 31 Message: fmt.Sprintf("limit parameter value %q is not a
number: %s", sLimit, err), |
| 32 Code: http.StatusBadRequest, |
| 33 } |
| 34 } |
| 35 if limit < 0 { |
| 36 return -1, &miloerror.Error{ |
| 37 Message: fmt.Sprintf("limit parameter value %q is less t
han 0", sLimit), |
| 38 Code: http.StatusBadRequest, |
| 39 } |
| 40 } |
| 41 return limit, nil |
| 42 } |
| OLD | NEW |