GoTomato/pkg/models/client.go
Sebastian Mark 600d2ed2ff feat: implement centralized logging helper
- remove direct log usage
- create a new logging helper
- update all log calls to use the new Logger instance
- set timestamp to ISO8601

🤖
2024-11-04 20:33:25 +01:00

31 lines
922 B
Go

package models
import (
"github.com/gorilla/websocket"
"git.smsvc.net/pomodoro/GoTomato/internal/helper"
)
// Represents a command from the client (start/stop)
type ClientCommand struct {
Command string `json:"command"` // Command send to the server
Password string `json:"password"` // Pomodoro control password
Settings PomodoroConfig `json:"settings"` // Pomodoro config
}
// Represents a single client
type WebsocketClient struct {
Conn *websocket.Conn
RealIP string
}
// Sends a message to the websocket.
// Automatically locks and unlocks the client mutex, to ensure that only one goroutine can write at a time.
func (c *WebsocketClient) SendMessage(messageType int, data []byte) error {
err := c.Conn.WriteMessage(messageType, data)
if err != nil {
helper.Logger.Error("Error writing to WebSocket:", "msg", err)
c.Conn.Close() // Close the connection on error
}
return err
}