feat: refactor connection handling to use models.Client
- introduce `Client` model
- modify all websocket operations to use the new `Client` model
- update function signatures to accept `models.Client` instead of `*websocket.Conn`
- ensure consistent usage of `client` across all related functions
🤖
This commit is contained in:
parent
f1071f33c6
commit
b943c9d6eb
6 changed files with 26 additions and 24 deletions
internal/websocket
|
@ -5,38 +5,39 @@ import (
|
|||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
func sendClientCommand(conn *websocket.Conn, msg GoTomato.ClientCommand) {
|
||||
func sendClientCommand(client ChronoTomato.Client, msg GoTomato.ClientCommand) {
|
||||
messageBytes, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
log.Error("Error marshalling!", "reason", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = conn.WriteMessage(websocket.TextMessage, messageBytes)
|
||||
err = client.Conn.WriteMessage(websocket.TextMessage, messageBytes)
|
||||
if err != nil {
|
||||
log.Error("Write error!", "reason", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
|
||||
func SendCmd(client ChronoTomato.Client, pwd string, cmd string) {
|
||||
message := GoTomato.ClientCommand{
|
||||
Command: cmd,
|
||||
Password: pwd,
|
||||
}
|
||||
|
||||
sendClientCommand(conn, message)
|
||||
sendClientCommand(client, message)
|
||||
}
|
||||
|
||||
func Send_updateSettings(conn *websocket.Conn, pwd string, settings GoTomato.PomodoroConfig) {
|
||||
func Send_updateSettings(client ChronoTomato.Client, pwd string, settings GoTomato.PomodoroConfig) {
|
||||
message := GoTomato.ClientCommand{
|
||||
Command: "updateSettings",
|
||||
Password: pwd,
|
||||
Settings: settings,
|
||||
}
|
||||
|
||||
sendClientCommand(conn, message)
|
||||
sendClientCommand(client, message)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue