URLParamInt returns the url query parameter as int value from a request, returns -1 and an error if parse failed or not found.
(name string)
| 1583 | // URLParamInt returns the url query parameter as int value from a request, |
| 1584 | // returns -1 and an error if parse failed or not found. |
| 1585 | func (ctx *Context) URLParamInt(name string) (int, error) { |
| 1586 | if v := ctx.URLParam(name); v != "" { |
| 1587 | n, err := strconv.Atoi(v) |
| 1588 | if err != nil { |
| 1589 | return -1, err |
| 1590 | } |
| 1591 | return n, nil |
| 1592 | } |
| 1593 | |
| 1594 | return -1, ErrNotFound |
| 1595 | } |
| 1596 | |
| 1597 | // URLParamIntDefault returns the url query parameter as int value from a request, |
| 1598 | // if not found or parse failed then "def" is returned. |
no test coverage detected