Edit messages
This commit is contained in:
parent
4fe6fed8c4
commit
abbc156fd8
1 changed files with 12 additions and 2 deletions
14
main.go
14
main.go
|
@ -69,6 +69,18 @@ func sendMsg(writer http.ResponseWriter, request *http.Request) {
|
||||||
func editMsg(writer http.ResponseWriter, request *http.Request) {
|
func editMsg(writer http.ResponseWriter, request *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
params := mux.Vars(request)
|
||||||
|
for _, msg := range chat {
|
||||||
|
if msg.Id == params["id"] {
|
||||||
|
_ = json.NewDecoder(request.Body).Decode(&(msg.Content))
|
||||||
|
msg.Content.Content = "(Edited) " + msg.Content.Content
|
||||||
|
fmt.Println("Edited Message:")
|
||||||
|
fmt.Println("#", msg.Id, msg.Content.Author, ":", msg.Content.Content)
|
||||||
|
//chat = append(chat[:index], chat[index+1:]...)
|
||||||
|
json.NewEncoder(writer).Encode(chat)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
func deleteMsg(writer http.ResponseWriter, request *http.Request) {
|
func deleteMsg(writer http.ResponseWriter, request *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
|
@ -110,6 +122,4 @@ func main() {
|
||||||
|
|
||||||
last := Message{"-1", Text{"The chat room is closed.", "SERVER"}}
|
last := Message{"-1", Text{"The chat room is closed.", "SERVER"}}
|
||||||
chat = append(chat, last)
|
chat = append(chat, last)
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue