feat: create shared config defaults
- add shared configuration defaults for server and pomodoro
🤖
This commit is contained in:
parent
28342058aa
commit
a9d145ee71
3 changed files with 26 additions and 11 deletions
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/websocket"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"log"
|
||||
|
@ -11,8 +12,8 @@ import (
|
|||
|
||||
func Start() {
|
||||
// Define CLI flags for ListenAddress and ListenPort
|
||||
listenAddress := flag.String("listenAddress", "0.0.0.0", "IP address to listen on")
|
||||
listenPort := flag.Int("listenPort", 8080, "Port to listen on")
|
||||
listenAddress := flag.String("listenAddress", shared.DefaultServerConfig.ListenAddress, "IP address to listen on")
|
||||
listenPort := flag.Int("listenPort", shared.DefaultServerConfig.ListenPort, "Port to listen on")
|
||||
flag.Parse()
|
||||
|
||||
serverConfig := models.GoTomatoServerConfig{
|
||||
|
|
20
internal/shared/configDefaults.go
Normal file
20
internal/shared/configDefaults.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
var DefaultServerConfig = models.GoTomatoServerConfig{
|
||||
ListenAddress: "0.0.0.0",
|
||||
ListenPort: 8080,
|
||||
}
|
||||
|
||||
var DefaultPomodoroConfig = models.GoTomatoPomodoroConfig{
|
||||
Work: 25 * 60,
|
||||
ShortBreak: 5 * 60,
|
||||
LongBreak: 15 * 60,
|
||||
Sessions: 4,
|
||||
}
|
||||
|
||||
// used to check if client passed a config json
|
||||
var UnsetPomodoroConfig models.GoTomatoPomodoroConfig
|
|
@ -3,23 +3,17 @@ package websocket
|
|||
import (
|
||||
"encoding/json"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/pomodoro"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
)
|
||||
|
||||
var unsetPomodoroConfig models.GoTomatoPomodoroConfig // used to check if client passed a config json
|
||||
|
||||
// handleClientCommands listens for commands from WebSocket clients
|
||||
func handleClientCommands(ws *websocket.Conn) {
|
||||
for {
|
||||
var clientCommand models.ClientCommand
|
||||
var pomodoroConfig = models.GoTomatoPomodoroConfig{
|
||||
Work: 25 * 60,
|
||||
ShortBreak: 5 * 60,
|
||||
LongBreak: 15 * 60,
|
||||
Sessions: 4,
|
||||
}
|
||||
var pomodoroConfig = shared.DefaultPomodoroConfig
|
||||
|
||||
_, message, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
|
@ -39,7 +33,7 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
switch clientCommand.Command {
|
||||
case "start":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
if clientCommand.Config != unsetPomodoroConfig {
|
||||
if clientCommand.Config != shared.UnsetPomodoroConfig {
|
||||
pomodoroConfig = clientCommand.Config
|
||||
}
|
||||
go pomodoro.RunPomodoro(pomodoroConfig) // Start the timer with the list of clients
|
||||
|
|
Loading…
Reference in a new issue