-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
27 lines (22 loc) · 895 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
package main
import (
"fmt"
"github.com/redis-developer/basic-redis-chat-demo-go/config"
"github.com/redis-developer/basic-redis-chat-demo-go/message"
"github.com/redis-developer/basic-redis-chat-demo-go/rediscli"
"github.com/redis-developer/basic-redis-chat-demo-go/websocket"
"log"
"net/http"
)
func main() {
cnf := config.NewConfig()
log.Println(fmt.Sprintf("%+v", cnf))
redisCli := rediscli.NewRedis(cnf.RedisAddress, cnf.RedisPassword)
messageController := message.NewController(redisCli)
http.Handle("/ws", websocket.Handler(redisCli, messageController))
http.HandleFunc("/links", func(writer http.ResponseWriter, request *http.Request) {
_,_ = writer.Write([]byte(`{"github":"https://github.com/redis-developer/basic-redis-chat-demo-go"}`))
})
http.Handle("/", http.FileServer(http.Dir(cnf.ClientLocation)))
log.Fatal(http.ListenAndServe(cnf.ServerAddress, nil))
}