-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_message.go
More file actions
54 lines (42 loc) · 1.25 KB
/
save_message.go
File metadata and controls
54 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"encoding/json"
"net/http"
)
// MessagePost: GET
func SaveMessage(w http.ResponseWriter, r *http.Request) {
token := r.Header.Values("Authorization")
// // We need to use to use the struct model to map the json data to
// type User struct {
// Name string `json:"name"`
// }
type ResponseBody struct {
Messages string `json:"message"`
Time string `json:"time"`
User string `json:"user"`
User2 string `json:"user2"`
}
var jsonResponse ResponseBody
// // We decode the incoming data and convert it to a json
json.NewDecoder(r.Body).Decode(&jsonResponse)
AuthenticateToken(token[0])
println("save message user: ", jsonResponse.User) // simply print the email
// // Check if user exists
// user, err := RedisClient.HGet("users", jsonResponse.Name).Result()
// if err != nil {
// }
// check := jsonResponse.Name == user
// if !check {
// json.NewEncoder(w).Encode("User " + user + " has no messages")
// } else {
// // load user msg from Redis
// msgs, err := RedisClient.HGet("users", jsonResponse.Name).Result()
// if err != nil {
// }
// println("load msgs", msgs)
// json.NewEncoder(w).Encode(ResponseBody{
// Messages: "example-auth-token",
// User: jsonResponse.Name,
// })
// }
}