func (a *App) onMessage(ctx context.Context, s *live.Session, topic string, data []byte) {
switch topic {
case "increment":
a.count++
case "decrement":
a.count--
}
// Re-render and broadcast to all clients
html := a.renderCounter()
a.liveServer.Publish("counter", "update", []byte(html))
}
func (a *App) renderCounter() string {
return fmt.Sprintf(`
<div class="counter">
<h1>%d</h1>
<div class="buttons">
<button onclick="live.send('decrement', '')">-</button>
<button onclick="live.send('increment', '')">+</button>
</div>
</div>
`, a.count)
}