-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_users.go
More file actions
47 lines (36 loc) · 860 Bytes
/
all_users.go
File metadata and controls
47 lines (36 loc) · 860 Bytes
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
package main
import (
"encoding/json"
"fmt"
"net/http"
)
// MessagePost: POST
func AllUsers(w http.ResponseWriter, r *http.Request) {
// query := r.URL.Query()
// name := query["user"][0]
// fmt.Println(name)
var jsonResponse UserResponse
// 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
}
}
}