- Add brotli compression (level 5) to long-lived SSE event streams (HandleGameEvents, HandleSnakeEvents) to reduce wire payload - Fix all errcheck violations with nolint annotations for best-effort calls - Fix goimports: separate stdlib, third-party, and local import groups - Fix staticcheck: add package comments, use tagged switch - Zero lint issues remaining
32 lines
888 B
Go
32 lines
888 B
Go
// Package c4game handles Connect 4 game routes, SSE event streaming, and chat.
|
|
package c4game
|
|
|
|
import (
|
|
"github.com/alexedwards/scs/v2"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/ryanhamamura/c4/db/repository"
|
|
"github.com/ryanhamamura/c4/game"
|
|
)
|
|
|
|
func SetupRoutes(
|
|
router chi.Router,
|
|
store *game.GameStore,
|
|
nc *nats.Conn,
|
|
sessions *scs.SessionManager,
|
|
queries *repository.Queries,
|
|
) error {
|
|
router.Get("/game/{game_id}", HandleGamePage(store, sessions, queries))
|
|
router.Get("/game/{game_id}/events", HandleGameEvents(store, nc, sessions, queries))
|
|
|
|
router.Route("/api/game/{game_id}", func(r chi.Router) {
|
|
r.Post("/drop", HandleDropPiece(store, sessions))
|
|
r.Post("/chat", HandleSendChat(store, nc, sessions, queries))
|
|
r.Post("/join", HandleSetNickname(store, sessions))
|
|
r.Post("/rematch", HandleRematch(store, sessions))
|
|
})
|
|
|
|
return nil
|
|
}
|