feat: add CLI flags to app

- implement command-line flags for listen address and port
- add usage section to README

🤖
This commit is contained in:
Sebastian Mark 2024-10-20 14:55:02 +02:00
parent 85923b4469
commit 0b2f83cd35
3 changed files with 17 additions and 7 deletions

View file

@ -6,6 +6,10 @@ A pomodoro server written in Go
`go install git.smsvc.net/pomodoro/GoTomato@latest` `go install git.smsvc.net/pomodoro/GoTomato@latest`
## Usage
See `GoTomato --help` for Parameters
## Testing ## Testing
``` ```

View file

@ -1,6 +1,7 @@
package server package server
import ( import (
"flag"
"fmt" "fmt"
"git.smsvc.net/pomodoro/GoTomato/internal/websocket" "git.smsvc.net/pomodoro/GoTomato/internal/websocket"
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
@ -8,12 +9,17 @@ import (
"net/http" "net/http"
) )
var serverConfig = models.GoTomatoServerConfig{ func Start() {
ListenAddress: "0.0.0.0", // Define CLI flags for ListenAddress and ListenPort
ListenPort: 8080, listenAddress := flag.String("listenAddress", "0.0.0.0", "IP address to listen on")
listenPort := flag.Int("listenPort", 8080, "Port to listen on")
flag.Parse()
serverConfig := models.GoTomatoServerConfig{
ListenAddress: *listenAddress,
ListenPort: *listenPort,
} }
func Start() {
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort) listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
http.HandleFunc("/ws", websocket.HandleConnections) http.HandleFunc("/ws", websocket.HandleConnections)

View file

@ -8,6 +8,6 @@ type GoTomatoTimerConfig struct {
} }
type GoTomatoServerConfig struct { type GoTomatoServerConfig struct {
ListenAddress string `json:"listenAddress"` ListenAddress string `json:"listenAddress, default:"0.0.0.0"`
ListenPort int `json:"listenPort"` ListenPort int `json:"listenPort, default:8080"`
} }