dockerize event proxy go app

This commit is contained in:
Travis Shears 2025-12-25 11:34:42 +01:00
parent aa5a4eda05
commit 83e3765247
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
5 changed files with 63 additions and 8 deletions

View file

@ -18,9 +18,20 @@ type App struct {
}
func getMQTTClient() mqtt.Client {
// TODO: get port and host from env vars
mqttHost := os.Getenv("MQTT_HOST")
if mqttHost == "" {
panic("MQTT_HOST environment variable not set")
}
mqttPort := os.Getenv("MQTT_PORT")
if mqttPort == "" {
panic("MQTT_PORT environment variable not set")
}
brokerURL := "tcp://" + mqttHost + ":" + mqttPort
slog.Info("Connecting to MQTT", "broker", brokerURL)
opts := mqtt.NewClientOptions().
AddBroker("tcp://localhost:5883").
AddBroker(brokerURL).
SetClientID("event-proxy")
client := mqtt.NewClient(opts)
@ -29,11 +40,6 @@ func getMQTTClient() mqtt.Client {
panic(token.Error())
}
return client
// // Publish a message
// token := client.Publish("homeassistant/sensor/bws/node1/state1", 0, false, `{"temp": 23.5, "humidity": 45, "pressure": 1013}`)
// token.Wait()
// client.Disconnect(250)
}
type Message struct {