-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (30 loc) · 761 Bytes
/
main.go
File metadata and controls
37 lines (30 loc) · 761 Bytes
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
package main
import (
"embed"
"fmt"
"log"
"net/http"
"os"
"github.com/stuartgrigg/qandagame/engine"
"github.com/stuartgrigg/qandagame/logging"
"github.com/stuartgrigg/qandagame/server"
)
// Embed the templates directory
//go:embed static/templates
var templatesFS embed.FS
func main() {
address := os.Getenv("SERVER_ADDRESS")
logger := logging.NewLogger("logs.txt")
defer logger.Close()
fmt.Println("Starting worker")
w, updates := engine.NewWorker(logger)
go w.Run()
fmt.Println("Starting server")
s := server.NewServer(w, updates, templatesFS)
go s.GameUpdateBroadcaster()
http.HandleFunc("/ws", s.WebSocketHandler)
http.HandleFunc("/", s.RootHandler)
if err := http.ListenAndServe(address, nil); err != nil {
log.Fatal(err)
}
}