OptionalInt returns the integer in req given by param, or 0 if not present. If the form value is not an integer, it panics with a a value understood by Recover or RecoverJSON.
(req *http.Request, param string)
| 242 | // OptionalInt returns the integer in req given by param, or 0 if not present. |
| 243 | // If the form value is not an integer, it panics with a a value understood by Recover or RecoverJSON. |
| 244 | func OptionalInt(req *http.Request, param string) int { |
| 245 | v := req.FormValue(param) |
| 246 | if v == "" { |
| 247 | return 0 |
| 248 | } |
| 249 | i, err := strconv.Atoi(v) |
| 250 | if err != nil { |
| 251 | panic(InvalidParameterError(param)) |
| 252 | } |
| 253 | return i |
| 254 | } |
| 255 | |
| 256 | // ServeJSONError sends a JSON error response to rw for the provided |
| 257 | // error value. |
no test coverage detected