mirror of
https://github.com/trafficlunar/api.git
synced 2026-06-27 22:24:08 +00:00
feat: computer data uptime
also fix last commit
This commit is contained in:
parent
02740548de
commit
84dfe05de8
3 changed files with 13 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
|
@ -36,12 +37,14 @@ func HandleComputerWebSocket(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
slog.Info("WebSocket connection established")
|
||||
service.ComputerData.Online = true
|
||||
service.ComputerData.UptimeStart = int(time.Now().Unix())
|
||||
|
||||
for {
|
||||
_, message, err := conn.ReadMessage()
|
||||
if err != nil {
|
||||
slog.Error("WebSocket connection closed by client", slog.Any("error", err))
|
||||
service.ComputerData.Online = false
|
||||
service.ComputerData.UptimeStart = 0
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue