fix: resolve all linting errors and add SSE compression
- 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:
@@ -1,3 +1,4 @@
|
||||
// Package snake implements snake game logic, state management, and persistence.
|
||||
package snake
|
||||
|
||||
import "math/rand"
|
||||
|
||||
@@ -62,7 +62,7 @@ func (si *SnakeGameInstance) countdownPhase() {
|
||||
si.game.Status = StatusInProgress
|
||||
|
||||
if si.queries != nil {
|
||||
si.saveSnakeGame(si.game)
|
||||
si.saveSnakeGame(si.game) //nolint:errcheck
|
||||
}
|
||||
si.gameMu.Unlock()
|
||||
si.notify()
|
||||
@@ -70,7 +70,7 @@ func (si *SnakeGameInstance) countdownPhase() {
|
||||
}
|
||||
|
||||
if si.queries != nil {
|
||||
si.saveSnakeGame(si.game)
|
||||
si.saveSnakeGame(si.game) //nolint:errcheck
|
||||
}
|
||||
si.gameMu.Unlock()
|
||||
si.notify()
|
||||
@@ -124,7 +124,7 @@ func (si *SnakeGameInstance) gamePhase() {
|
||||
if time.Since(lastInput) > inactivityLimit {
|
||||
si.game.Status = StatusFinished
|
||||
if si.queries != nil {
|
||||
si.saveSnakeGame(si.game)
|
||||
si.saveSnakeGame(si.game) //nolint:errcheck
|
||||
}
|
||||
si.gameMu.Unlock()
|
||||
si.notify()
|
||||
@@ -196,7 +196,7 @@ func (si *SnakeGameInstance) gamePhase() {
|
||||
}
|
||||
|
||||
if si.queries != nil {
|
||||
si.saveSnakeGame(si.game)
|
||||
si.saveSnakeGame(si.game) //nolint:errcheck
|
||||
}
|
||||
|
||||
si.gameMu.Unlock()
|
||||
|
||||
@@ -63,7 +63,7 @@ func (ss *SnakeStore) Create(width, height int, mode GameMode, speed int) *Snake
|
||||
ss.gamesMu.Unlock()
|
||||
|
||||
if ss.queries != nil {
|
||||
ss.saveSnakeGame(sg)
|
||||
ss.saveSnakeGame(sg) //nolint:errcheck
|
||||
}
|
||||
|
||||
return si
|
||||
@@ -207,8 +207,8 @@ func (si *SnakeGameInstance) Join(player *Player) bool {
|
||||
si.game.Players[slot] = player
|
||||
|
||||
if si.queries != nil {
|
||||
si.saveSnakePlayer(si.game.ID, player)
|
||||
si.saveSnakeGame(si.game)
|
||||
si.saveSnakePlayer(si.game.ID, player) //nolint:errcheck
|
||||
si.saveSnakeGame(si.game) //nolint:errcheck
|
||||
}
|
||||
|
||||
si.notify()
|
||||
@@ -294,7 +294,7 @@ func (si *SnakeGameInstance) CreateRematch() *SnakeGameInstance {
|
||||
si.game.RematchGameID = &newID
|
||||
|
||||
if si.queries != nil {
|
||||
si.saveSnakeGame(si.game)
|
||||
si.saveSnakeGame(si.game) //nolint:errcheck
|
||||
}
|
||||
si.gameMu.Unlock()
|
||||
|
||||
@@ -304,6 +304,6 @@ func (si *SnakeGameInstance) CreateRematch() *SnakeGameInstance {
|
||||
|
||||
func generateID(size int) string {
|
||||
b := make([]byte, size)
|
||||
rand.Read(b)
|
||||
_, _ = rand.Read(b)
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ type SnakeGame struct {
|
||||
Speed int // cells per second
|
||||
}
|
||||
|
||||
// Speed presets
|
||||
// SpeedPreset defines a named speed option for the snake game.
|
||||
type SpeedPreset struct {
|
||||
Name string
|
||||
Speed int
|
||||
@@ -129,7 +129,7 @@ func (sg *SnakeGame) PlayerCount() int {
|
||||
return count
|
||||
}
|
||||
|
||||
// Grid presets
|
||||
// GridPreset defines a named grid size option for the snake game.
|
||||
type GridPreset struct {
|
||||
Name string
|
||||
Width int
|
||||
@@ -163,7 +163,7 @@ func (sg *SnakeGame) snapshot() *SnakeGame {
|
||||
return &cp
|
||||
}
|
||||
|
||||
// Snake colors (hex values for CSS)
|
||||
// SnakeColors are hex color values for CSS, indexed by player slot.
|
||||
var SnakeColors = []string{
|
||||
"#00b894", // 1: Green
|
||||
"#e17055", // 2: Orange
|
||||
|
||||
Reference in New Issue
Block a user