aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/main.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-04 22:55:01 +0900
committernsfisis <nsfisis@gmail.com>2025-03-08 10:12:44 +0900
commit1e6df136d8202c8adf65948527f4c3e7583b338c (patch)
tree7c82476f6bbbc71d72ab7e71e39559eca197fd95 /backend/main.go
parent54316868c3bec1ff9b04643dfe6c13cf56bf3246 (diff)
downloadphperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.gz
phperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.zst
phperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.zip
websocket to polling
Diffstat (limited to 'backend/main.go')
-rw-r--r--backend/main.go32
1 files changed, 8 insertions, 24 deletions
diff --git a/backend/main.go b/backend/main.go
index 1218b19..3df5d83 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -61,29 +61,16 @@ func main() {
e.Use(middleware.Recover())
taskQueue := taskqueue.NewQueue("task-db:6379")
- workerServer := taskqueue.NewWorkerServer("task-db:6379", queries)
+ workerServer := taskqueue.NewWorkerServer("task-db:6379")
- gameHubs := game.NewGameHubs(queries, taskQueue, workerServer.Results())
- err = gameHubs.RestoreFromDB(ctx)
- if err != nil {
- log.Fatalf("Error restoring game hubs from db %v", err)
- }
- defer gameHubs.Close()
- sockGroup := e.Group("/phperkaigi/2025/code-battle/sock")
- sockHandler := gameHubs.SockHandler()
- sockGroup.GET("/golf/:gameID/play", func(c echo.Context) error {
- return sockHandler.HandleSockGolfPlay(c)
- })
- sockGroup.GET("/golf/:gameID/watch", func(c echo.Context) error {
- return sockHandler.HandleSockGolfWatch(c)
- })
+ gameHub := game.NewGameHub(queries, taskQueue, workerServer)
apiGroup := e.Group("/phperkaigi/2025/code-battle/api")
apiGroup.Use(oapimiddleware.OapiRequestValidator(openAPISpec))
- apiHandler := api.NewHandler(queries, gameHubs)
+ apiHandler := api.NewHandler(queries, gameHub)
api.RegisterHandlers(apiGroup, api.NewStrictHandler(apiHandler, nil))
- adminHandler := admin.NewHandler(queries, gameHubs)
+ adminHandler := admin.NewHandler(queries, gameHub)
adminGroup := e.Group("/phperkaigi/2025/code-battle/admin")
adminHandler.RegisterHandlers(adminGroup)
@@ -105,15 +92,12 @@ func main() {
e.POST("/phperkaigi/2025/code-battle/*", func(c echo.Context) error {
return c.Redirect(http.StatusPermanentRedirect, "http://localhost:5173"+c.Request().URL.Path)
})
- }
- go gameHubs.Run()
+ // Allow access from dev server.
+ e.Use(middleware.CORS())
+ }
- go func() {
- if err := workerServer.Run(); err != nil {
- log.Fatal(err)
- }
- }()
+ go gameHub.Run()
if err := e.Start(":80"); err != http.ErrServerClosed {
log.Fatal(err)