summaryrefslogtreecommitdiffstats
path: root/api4/params.go
diff options
context:
space:
mode:
Diffstat (limited to 'api4/params.go')
-rw-r--r--api4/params.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/api4/params.go b/api4/params.go
index 452b9ba21..1c0c153ea 100644
--- a/api4/params.go
+++ b/api4/params.go
@@ -5,10 +5,17 @@ package api4
import (
"net/http"
+ "strconv"
"github.com/gorilla/mux"
)
+const (
+ PAGE_DEFAULT = 0
+ PER_PAGE_DEFAULT = 60
+ PER_PAGE_MAXIMUM = 200
+)
+
type ApiParams struct {
UserId string
TeamId string
@@ -18,6 +25,8 @@ type ApiParams struct {
CommandId string
HookId string
EmojiId string
+ Page int
+ PerPage int
}
func ApiParamsFromRequest(r *http.Request) *ApiParams {
@@ -57,5 +66,19 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams {
params.EmojiId = val
}
+ if val, err := strconv.Atoi(r.URL.Query().Get("page")); err != nil {
+ params.Page = PAGE_DEFAULT
+ } else {
+ params.Page = val
+ }
+
+ if val, err := strconv.Atoi(r.URL.Query().Get("per_page")); err != nil {
+ params.PerPage = PER_PAGE_DEFAULT
+ } else if val > PER_PAGE_MAXIMUM {
+ params.PerPage = PER_PAGE_MAXIMUM
+ } else {
+ params.PerPage = val
+ }
+
return params
}