Add config options for ListenAddr & Interfaces

These options are helpful when the bridge is running on a multi-homed
device like a wireless router.
This commit is contained in:
Darell Tan
2023-08-03 23:28:52 +08:00
parent 3cfc3f68b0
commit 59b049faea
4 changed files with 50 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"os/signal"
@@ -29,7 +30,11 @@ var (
debugMode = flag.Bool("debug", false, "enable debug messages")
)
// config struct
type config struct {
ListenAddr string
Interfaces []string
Server, Username, Password string
}
@@ -73,6 +78,17 @@ func main() {
br.Password = cfg.Password
br.DebugMode = *debugMode
// validate ListenAddr if specified
if cfg.ListenAddr != "" {
_, _, err := net.SplitHostPort(cfg.ListenAddr)
if err != nil {
log.Fatalf("invalid ListenAddr: %v", err)
}
br.ListenAddr = cfg.ListenAddr
}
br.Interfaces = cfg.Interfaces
err = br.ConnectMQTT()
if err != nil {
log.Printf("cannot connect to MQTT: %s", err)