forked from AntonioVdlC/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (37 loc) · 1.03 KB
/
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
45
46
47
package main
import (
"log"
"net/http"
)
func main() {
db := initDB()
defer db.Close()
hub := newHub(db)
go hub.run()
loadSession()
loadLocales()
http.HandleFunc("/", home)
http.HandleFunc("/login", login)
http.HandleFunc("/auth/callback", authCallback)
http.HandleFunc("/logout", logout)
http.HandleFunc("/auth", auth)
http.HandleFunc("/chat", chat)
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
hub.setT(initT(r.Header.Get("Accept-Language"), "en"))
serveWs(hub, w, r)
})
http.HandleFunc("/service-worker.js", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "public/service-worker.js")
})
http.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "public/robots.txt")
})
fs := http.FileServer(http.Dir("public"))
http.Handle("/public/", http.StripPrefix("/public/", fs))
port := getPort()
log.Printf("Listening on port %s", port)
err := http.ListenAndServe(port, nil)
if err != nil {
log.Printf("Error: %v", err)
}
}