From c01d9ad6cf3f8bb2ad4145441816598d8ffa2d9e Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 30 Jan 2017 08:30:02 -0500 Subject: Implement APIv4 infrastructure (#5191) * Implement APIv4 infrastructure * Update parameter requirement functions per feedback --- api4/params.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 api4/params.go (limited to 'api4/params.go') diff --git a/api4/params.go b/api4/params.go new file mode 100644 index 000000000..452b9ba21 --- /dev/null +++ b/api4/params.go @@ -0,0 +1,61 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package api4 + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +type ApiParams struct { + UserId string + TeamId string + ChannelId string + PostId string + FileId string + CommandId string + HookId string + EmojiId string +} + +func ApiParamsFromRequest(r *http.Request) *ApiParams { + params := &ApiParams{} + + props := mux.Vars(r) + + if val, ok := props["user_id"]; ok { + params.UserId = val + } + + if val, ok := props["team_id"]; ok { + params.TeamId = val + } + + if val, ok := props["channel_id"]; ok { + params.ChannelId = val + } + + if val, ok := props["post_id"]; ok { + params.PostId = val + } + + if val, ok := props["file_id"]; ok { + params.FileId = val + } + + if val, ok := props["command_id"]; ok { + params.CommandId = val + } + + if val, ok := props["hook_id"]; ok { + params.HookId = val + } + + if val, ok := props["emoji_id"]; ok { + params.EmojiId = val + } + + return params +} -- cgit v1.2.3-1-g7c22