From 36dab8b5182215d53512525991cc23523bdf23dc Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 9 Jun 2018 19:13:41 -0700 Subject: Add more filters for API call /entries New filters: - before (unix timestamp) - before_entry_id - after - after_entry_id - starred (boolean) --- http/request/request.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'http') diff --git a/http/request/request.go b/http/request/request.go index 1de6f73..cc5a4dd 100644 --- a/http/request/request.go +++ b/http/request/request.go @@ -24,11 +24,15 @@ func Cookie(r *http.Request, name string) string { return cookie.Value } -// FormIntValue returns a form value as integer. -func FormIntValue(r *http.Request, param string) int64 { +// FormInt64Value returns a form value as integer. +func FormInt64Value(r *http.Request, param string) int64 { value := r.FormValue(param) - integer, _ := strconv.Atoi(value) - return int64(integer) + integer, err := strconv.ParseInt(value, 10, 64) + if err != nil { + return 0 + } + + return integer } // IntParam returns an URL route parameter as integer. @@ -67,12 +71,17 @@ func QueryParam(r *http.Request, param, defaultValue string) string { // QueryIntParam returns a querystring parameter as integer. func QueryIntParam(r *http.Request, param string, defaultValue int) int { + return int(QueryInt64Param(r, param, int64(defaultValue))) +} + +// QueryInt64Param returns a querystring parameter as int64. +func QueryInt64Param(r *http.Request, param string, defaultValue int64) int64 { value := r.URL.Query().Get(param) if value == "" { return defaultValue } - val, err := strconv.Atoi(value) + val, err := strconv.ParseInt(value, 10, 64) if err != nil { return defaultValue } -- cgit v1.2.3