Skip to main content
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.

Step 1: Create the Project

Open http://localhost:8080 to see the default app.

Step 2: Understand the Counter

The template includes a counter example. Let’s examine how it works.

The Counter Handler

Look at handler/counter.go:

The Counter View

Look at views/pages/counter.html:

The WebSocket Handler

In app/server/app.go, messages are handled:

Step 3: Test Real-Time Updates

  1. Open http://localhost:8080/counter in one browser
  2. Open it in another browser window
  3. Click + or - in one window
  4. Watch both windows update!

Step 4: Add a Reset Button

Update the renderCounter function:
Handle the reset message:

Step 5: Add Per-User Counters

Each user can have their own counter:

How Live Updates Work

What You Learned

  • WebSocket connection handling
  • Message-based communication
  • Broadcasting updates to all clients
  • Per-session state management
  • Server-side rendering for updates

Next Steps

Sync Template

Add offline support and data sync

Live Documentation

Deep dive into live features