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:
parent
85923b4469
commit
0b2f83cd35
3 changed files with 17 additions and 7 deletions
|
@ -6,6 +6,10 @@ A pomodoro server written in Go
|
|||
|
||||
`go install git.smsvc.net/pomodoro/GoTomato@latest`
|
||||
|
||||
## Usage
|
||||
|
||||
See `GoTomato --help` for Parameters
|
||||
|
||||
## Testing
|
||||
|
||||
```
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/websocket"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
|
@ -8,12 +9,17 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
var serverConfig = models.GoTomatoServerConfig{
|
||||
ListenAddress: "0.0.0.0",
|
||||
ListenPort: 8080,
|
||||
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")
|
||||
flag.Parse()
|
||||
|
||||
serverConfig := models.GoTomatoServerConfig{
|
||||
ListenAddress: *listenAddress,
|
||||
ListenPort: *listenPort,
|
||||
}
|
||||
|
||||
func Start() {
|
||||
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
|
||||
|
||||
http.HandleFunc("/ws", websocket.HandleConnections)
|
||||
|
|
|
@ -8,6 +8,6 @@ type GoTomatoTimerConfig struct {
|
|||
}
|
||||
|
||||
type GoTomatoServerConfig struct {
|
||||
ListenAddress string `json:"listenAddress"`
|
||||
ListenPort int `json:"listenPort"`
|
||||
ListenAddress string `json:"listenAddress, default:"0.0.0.0"`
|
||||
ListenPort int `json:"listenPort, default:8080"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue