-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (34 loc) · 868 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
package main
import (
"fmt"
"log"
"net/http"
)
// func serveHome(w http.ResponseWriter, r *http.Request) {
// log.Println(r.URL)
// if r.URL.Path != "/" {
// http.Error(w, "无", http.StatusNotFound)
// return
// }
// if r.Method != "GET" {
// http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
// return
// }
// http.ServeFile(w, r, "static/home.html")
// }
func main() {
hub := newHub()
//go hub.run()
http.Handle("/", http.FileServer(http.Dir("static")))
// TODO https://hack.chat/?your-channel
//URL query param
//all the params behind host is supposed to be split joint a particular channel
http.HandleFunc("/chat-ws", func(w http.ResponseWriter, r *http.Request) {
serveWs(hub, w, r)
})
fmt.Println("Listen on 8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe", err)
}
}