-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (31 loc) · 965 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
package main
import (
"context"
"fmt"
"log"
"net/http"
)
func main() {
// Create a root ctx and a CancelFunc which can be used to cancel retentionMap goroutine
rootCtx := context.Background()
ctx, cancel := context.WithCancel(rootCtx)
defer cancel()
setupAPI(ctx)
// Serve on port :8080, fudge yeah hardcoded port
err := http.ListenAndServeTLS(":8080", "server.crt", "server.key", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
// setupAPI will start all Routes and their Handlers
func setupAPI(ctx context.Context) {
// Create a Manager instance used to handle WebSocket Connections
manager := NewManager(ctx)
// Serve the ./frontend directory at Route /
http.Handle("/", http.FileServer(http.Dir("./frontend")))
http.HandleFunc("/login", manager.loginHandler)
http.HandleFunc("/ws", manager.serveWS)
http.HandleFunc("/debug", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, len(manager.clients))
})
}