mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 11:38:22 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user