diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-02-03 15:17:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-03 15:17:34 -0500 |
commit | 7ff2aef7facdeb025a1651ef411fceb3d81932c1 (patch) | |
tree | 7ea2f7b89e4b4c1acf3ca021377b0166089ba397 /api4/params.go | |
parent | 948b557453550646ad3213cb4144055eb7db0d69 (diff) | |
download | chat-7ff2aef7facdeb025a1651ef411fceb3d81932c1.tar.gz chat-7ff2aef7facdeb025a1651ef411fceb3d81932c1.tar.bz2 chat-7ff2aef7facdeb025a1651ef411fceb3d81932c1.zip |
Implement GET /users endpoint for APIv4 (#5277)
Diffstat (limited to 'api4/params.go')
-rw-r--r-- | api4/params.go | 23 |
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 } |