The project implements live reloading by establishing a WebSocket connection between the server and the client. It uses an fsnotify.Watcher to monitor file system changes. When a change is detected, a reload signal is sent through a channel, triggering the server to write a websocket.TextMessage containing the string "reload" to the client.
To maintain a stable connection, the server implements a heartbeat mechanism:
- Ping/Pong: The server sends periodic
websocket.PingMessage packets based on a pingPeriod (calculated as 90% of the pongWait interval). - Deadlines: The server sets a read deadline (
pongWait of 60 seconds) and updates it whenever a pong is received to ensure the connection remains active.
// Conceptual flow of the reload signal:
case <-reload:
err := socket.WriteMessage(websocket.TextMessage, []byte("reload"))