fix: resolve all linting errors and add SSE compression
Some checks failed
CI / Deploy / test (pull_request) Successful in 8s
CI / Deploy / lint (pull_request) Failing after 44s
CI / Deploy / deploy (pull_request) Has been skipped

- 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
This commit is contained in:
Ryan Hamamura
2026-03-02 12:38:21 -10:00
parent 2aa026b1d5
commit afd8a3e9d0
18 changed files with 67 additions and 41 deletions

View File

@@ -9,11 +9,12 @@ import (
"github.com/alexedwards/scs/v2"
"github.com/go-chi/chi/v5"
"github.com/nats-io/nats.go"
"github.com/starfederation/datastar-go/datastar"
"github.com/ryanhamamura/c4/features/snakegame/components"
"github.com/ryanhamamura/c4/features/snakegame/pages"
"github.com/ryanhamamura/c4/game"
"github.com/ryanhamamura/c4/snake"
"github.com/starfederation/datastar-go/datastar"
)
func getPlayerID(sessions *scs.SessionManager, r *http.Request) snake.PlayerID {
@@ -90,7 +91,9 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sessions *sc
playerID := getPlayerID(sessions, r)
mySlot := si.GetPlayerSlot(playerID)
sse := datastar.NewSSE(w, r)
sse := datastar.NewSSE(w, r, datastar.WithCompression(
datastar.WithBrotli(datastar.WithBrotliLevel(5)),
))
// Send initial render
sg := si.GetGame()
@@ -110,7 +113,7 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sessions *sc
if err != nil {
return
}
defer gameSub.Unsubscribe()
defer gameSub.Unsubscribe() //nolint:errcheck
// Chat subscription (multiplayer only)
var chatCh chan *nats.Msg
@@ -124,7 +127,7 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sessions *sc
if err != nil {
return
}
defer chatSub.Unsubscribe()
defer chatSub.Unsubscribe() //nolint:errcheck
}
ctx := r.Context()