feat: create model for server config
- introduce GoTomatoServerConfig
- create instance variable with the current config
- update server to use configurable listen address and port
🤖
This commit is contained in:
parent
3d5cb29c54
commit
09b475dd61
2 changed files with 17 additions and 2 deletions
|
@ -1,16 +1,25 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/websocket"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var serverConfig = models.GoTomatoServerConfig{
|
||||
ListenAddress: "0.0.0.0",
|
||||
ListenPort: 8080,
|
||||
}
|
||||
|
||||
func Start() {
|
||||
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
|
||||
|
||||
http.HandleFunc("/ws", websocket.HandleConnections)
|
||||
|
||||
log.Println("Pomodoro WebSocket server started on :8080")
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
log.Printf("Pomodoro WebSocket server started on %s\n", listen)
|
||||
err := http.ListenAndServe(listen, nil)
|
||||
if err != nil {
|
||||
log.Fatalf("Error starting server: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue