feat: validate client settings and improve logging
- add a function to check if Pomodoro settings are valid
- log a warning for invalid client configurations
- log an info message for valid client configurations
- implement Stringer interface for PomodoroConfig model
🤖
This commit is contained in:
parent
f4fd37c551
commit
e7618b19ef
2 changed files with 16 additions and 0 deletions
|
@ -9,6 +9,10 @@ import (
|
|||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
func checkSettings(settings models.PomodoroConfig) bool {
|
||||
return settings.Work > 0 && settings.ShortBreak > 0 && settings.LongBreak > 0 && settings.Sessions > 0
|
||||
}
|
||||
|
||||
// Listens for commands from a client and handles them
|
||||
func handleClientCommands(c models.WebsocketClient) {
|
||||
ws := c.Conn
|
||||
|
@ -50,6 +54,11 @@ func handleClientCommands(c models.WebsocketClient) {
|
|||
}
|
||||
case "updateSettings":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
if !checkSettings(clientCommand.Settings) {
|
||||
log.Warn("Ignoring invalid config:", "msg", clientCommand.Settings, "host", c.Conn.RemoteAddr())
|
||||
break
|
||||
}
|
||||
log.Info("Client send config", "config", clientCommand.Settings, "host", c.Conn.RemoteAddr())
|
||||
pomodoro.UpdateSettings(clientCommand.Settings)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue