Skip to content

Commit

Permalink
Replace env vars with command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelWei committed Jan 2, 2025
1 parent c037cb0 commit 71c58fd
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions room-hub/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"crypto/rand"
"encoding/json"
"flag"
"github.com/go-playground/validator/v10"
"github.com/gorilla/websocket"
"log"
"math/big"
"net/http"
"os"
"strconv"
)

var validate *validator.Validate
Expand Down Expand Up @@ -280,26 +281,17 @@ func pluginHandler(w http.ResponseWriter, r *http.Request) {
}

func main() {
host := flag.String("host", "127.0.0.1", "websocket server host")
port := flag.Int("port", 8080, "websocket server port")
flag.Parse()

validate = validator.New()

http.HandleFunc("/ws_room", roomHandler)
http.HandleFunc("/ws_plugin", pluginHandler)

host := os.Getenv("BBB_ROOM_HUB_HOST")
port := os.Getenv("BBB_ROOM_HUB_PORT")

// If host is set use it, otherwise use default 0.0.0.0
if host == "" {
host = "0.0.0.0"
}

// If port is set to use it, otherwise use default 8080
if port == "" {
port = "8080"
}

log.Printf("WebSocket server started on %s:%s", host, port)
err := http.ListenAndServe(host+":"+port, nil)
log.Printf("WebSocket server started on %s:%d", *host, *port)
err := http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
Expand Down

0 comments on commit 71c58fd

Please sign in to comment.