-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (38 loc) · 970 Bytes
/
main.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
package main
import (
_ "encoding/json"
"fmt"
"github.com/garyburd/redigo/redis"
_ "github.com/garyburd/redigo/redis"
"log"
"net/http"
)
// TODO: list all users from redis
func listUsers(w http.ResponseWriter, r *http.Request) {
// build connection
conn,err := redis.Dial("tcp","jupyter.neuyan.com:6379", redis.DialDatabase(1), redis.DialPassword("weneudb2019"))
if err != nil {
fmt.Println("connect redis error :",err)
return
}
defer conn.Close()
// get all keys
keys, err := conn.Do("KEYS", "*")
fmt.Println(keys)
if err != nil {
fmt.Println("redis KEYS error:", err)
}
}
func main() {
go broadcaster()
// upgrade http to websocket
http.HandleFunc("/test-ws", wsHandler)
http.HandleFunc("/login", QQLogin)
http.HandleFunc("/ws", wsHandler)
http.HandleFunc("/user", listUsers)
// monitor localhost:7777
err := http.ListenAndServe("0.0.0.0:7778", nil)
if err != nil {
log.Fatal("ListenAndServe Monitoring Error", err.Error())
}
}