-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_contacts.go
50 lines (38 loc) · 909 Bytes
/
all_contacts.go
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
package main
import (
"encoding/json"
"fmt"
"net/http"
)
// MessagePost: GET
func AllContacts(w http.ResponseWriter, r *http.Request) {
// TODO: Check token here
// query := r.URL.Query()
// name := query["user"][0]
// fmt.Println(name)
var jsonResponse UserResponse
// Check the user
// We decode the incoming data and convert it to a json this gets sent to the client
json.NewDecoder(r.Body).Decode(&jsonResponse)
println("Message to Server", jsonResponse.User) // simply print the email
all, err := RedisClient.HGetAll("names").Result()
if err != nil {
panic(err)
}
json.NewEncoder(w).Encode(all)
var cursor uint64
for {
var keys []string
var err error
keys, cursor, err = RedisClient.Scan(cursor, "names", 0).Result()
if err != nil {
panic(err)
}
for _, key := range keys {
fmt.Println("key", key)
}
if cursor == 0 { // no more keys
break
}
}
}