Genesis
This commit is contained in:
commit
11c599a371
11 changed files with 325 additions and 0 deletions
43
internal/websocket/send.go
Normal file
43
internal/websocket/send.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"ChronoTomato/config"
|
||||
"encoding/json"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func sendClientCommand(conn *websocket.Conn, msg models.ClientCommand) {
|
||||
messageBytes, err := json.Marshal(msg)
|
||||
|
||||
if err != nil {
|
||||
log.Error("Error marshalling!", "reason", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = conn.WriteMessage(websocket.TextMessage, messageBytes)
|
||||
if err != nil {
|
||||
log.Error("Write error!", "reason", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func SendCmd(conn *websocket.Conn, cmd string, pwd string) {
|
||||
message := models.ClientCommand{
|
||||
Command: cmd,
|
||||
Password: pwd,
|
||||
}
|
||||
|
||||
sendClientCommand(conn, message)
|
||||
}
|
||||
|
||||
func Send_updateSettings(conn *websocket.Conn, pwd string) {
|
||||
message := models.ClientCommand{
|
||||
Command: "updateSettings",
|
||||
Password: pwd,
|
||||
PomodoroSettings: config.PomodoroSettings,
|
||||
}
|
||||
|
||||
sendClientCommand(conn, message)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue