Beispiel #1
0
func ViewMessages(w http.ResponseWriter, r *http.Request, params martini.Params) (int, string) {
	chatidString := params["chatid"]
	chatid, err := strconv.Atoi(chatidString)
	utils.PanicIf(err)

	chat := store.ChatStore[chatid]
	return 200, string(utils.MustMarshal(chat.Messages))
}
Beispiel #2
0
func GetChats(w http.ResponseWriter, r *http.Request, params martini.Params) (int, string) {
	useridString := params["userid"]
	userid, err := strconv.Atoi(useridString)
	utils.PanicIf(err)

	user := store.Users[userid]
	return 200, string(utils.MustMarshal(user.Chats))
}
Beispiel #3
0
func NewChat(w http.ResponseWriter, r *http.Request, params martini.Params) (int, string) {
	decoder := json.NewDecoder(r.Body)
	var users []int
	err := decoder.Decode(&users)
	utils.PanicIf(err)

	chatid := store.NewChat(users)
	return 200, string(utils.MustMarshal(chatid))
}