Skip to content

Commit 78b3fc2

Browse files
committed
Add structured logging and health checks
Switched to slog for structured logging - JSON format for production servers and readable text for development. Added a proper health check endpoint that verifies storage connectivity. Made the error handling more robust with graceful server shutdown.
1 parent 4feb94d commit 78b3fc2

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ Use the `realtime.Hub` directly or the WebSocket adapter:
8282
http.Handle("/ws", ws.Handler(hub)) // stream events to clients
8383
```
8484

85+
### Leaderboards
86+
Efficient score tracking with Redis sorted sets:
87+
88+
```go
89+
import "gamifykit/leaderboard"
90+
91+
// Create a Redis leaderboard
92+
client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
93+
board := leaderboard.NewRedisBoard(client, "game:scores")
94+
95+
// Update scores
96+
board.Update("alice", 1500)
97+
board.Update("bob", 1200)
98+
99+
// Get top players
100+
topPlayers := board.TopN(10)
101+
102+
// Get specific player
103+
if entry, exists := board.Get("alice"); exists {
104+
fmt.Printf("%s has %d points\n", entry.User, entry.Score)
105+
}
106+
```
107+
85108
### Demo server
86109
Run a tiny HTTP server exposing points/badges and a WebSocket stream:
87110

leaderboard/redis.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package leaderboard
22

33
// Placeholder for a Redis-backed leaderboard using sorted sets.
4-
5-

0 commit comments

Comments
 (0)