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

	decoder := json.NewDecoder(r.Body)
	var message store.Message
	err = decoder.Decode(&message)
	utils.PanicIf(err)

	store.ChatStore[chatid].Messages = append(store.ChatStore[chatid].Messages, message)

	return 200, ""
}
示例#2
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))
}
示例#3
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))
}
示例#4
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))
}