refactor: replace via framework with chi + templ + datastar
Migrate from the via meta-framework to direct dependencies:
- chi for routing, templ for HTML templates, datastar for SSE/reactivity
- Feature-sliced architecture (features/{auth,lobby,c4game,snakegame}/)
- Shared layouts and components (features/common/)
- Handler factory pattern (HandleX(deps) http.HandlerFunc)
- Embedded NATS server (nats/), SCS sessions (sessions/), chi router wiring (router/)
- Move ChatMessage domain type from ui package to game package
- Remove old ui/ package (gomponents-based via/h views)
- Remove via dependency from go.mod entirely
This commit is contained in:
29
features/c4game/routes.go
Normal file
29
features/c4game/routes.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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"
|
||||
"github.com/ryanhamamura/c4/game"
|
||||
)
|
||||
|
||||
func SetupRoutes(
|
||||
router chi.Router,
|
||||
store *game.GameStore,
|
||||
nc *nats.Conn,
|
||||
sessions *scs.SessionManager,
|
||||
chatPersister *db.ChatPersister,
|
||||
) error {
|
||||
router.Get("/game/{game_id}", HandleGamePage(store, sessions, chatPersister))
|
||||
router.Get("/game/{game_id}/events", HandleGameEvents(store, nc, sessions, chatPersister))
|
||||
|
||||
router.Route("/api/game/{game_id}", func(r chi.Router) {
|
||||
r.Post("/drop", HandleDropPiece(store, sessions))
|
||||
r.Post("/chat", HandleSendChat(store, nc, sessions, chatPersister))
|
||||
r.Post("/join", HandleSetNickname(store, sessions))
|
||||
r.Post("/rematch", HandleRematch(store, sessions))
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user