Use this file to discover all available pages before exploring further.
In this tutorial, you’ll build an interactive counter that updates in real-time across all connected browsers. When one user clicks a button, everyone sees the change instantly. This is the foundation for chat apps, live dashboards, collaborative tools, and any feature that needs instant updates.
func (a *App) onMessage(ctx context.Context, s *live.Session, topic string, data []byte) { switch topic { case "increment": a.count++ case "decrement": a.count-- case "reset": a.count = 0 } html := a.renderCounter() a.liveServer.Publish("counter", "update", []byte(html))}
func (a *App) onConnect(ctx context.Context, s *live.Session) error { // Initialize per-session counter s.Set("count", 0) return nil}func (a *App) onMessage(ctx context.Context, s *live.Session, topic string, data []byte) { count := s.Get("count").(int) switch topic { case "increment": count++ case "decrement": count-- case "reset": count = 0 } s.Set("count", count) // Send update to this session only html := renderCounter(count) s.Send("update", []byte(html))}