| 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 common | |
| 6 | |
| 7 import ( | |
| 8 "fmt" | |
| 9 "net/http" | |
| 10 "strconv" | |
| 11 ) | |
| 12 | |
| 13 // GetLimit extracts the "limit", "numbuilds", or "num_builds" http param from | |
| 14 // the request, or returns "-1" implying no limit was specified. | |
| 15 func GetLimit(r *http.Request) (int, error) { | |
| 16 sLimit := r.FormValue("limit") | |
| 17 if sLimit == "" { | |
| 18 sLimit = r.FormValue("numbuilds") | |
| 19 if sLimit == "" { | |
| 20 sLimit = r.FormValue("num_builds") | |
| 21 if sLimit == "" { | |
| 22 return -1, nil | |
| 23 } | |
| 24 } | |
| 25 } | |
| 26 limit, err := strconv.Atoi(sLimit) | |
| 27 if err != nil { | |
| 28 return -1, fmt.Errorf("limit parameter value %q is not a number:
%s", sLimit, err) | |
| 29 } | |
| 30 if limit < 0 { | |
| 31 return -1, fmt.Errorf("limit parameter value %q is less than 0",
sLimit) | |
| 32 } | |
| 33 return limit, nil | |
| 34 } | |
| OLD | NEW |