Files
mqtt-archiver/src/ma/config/config.go
2026-01-12 22:32:18 +01:00

45 lines
1.0 KiB
Go

package config
import (
"encoding/json"
"log"
"os"
)
type HandlerConfigT struct {
Attributes map[string]string `json:"attributes"`
}
type ConfigT struct {
Mqtt struct {
Broker string `json:"broker"`
Username string `json:"username"`
Password string `json:"password"`
TlsEnable string `json:"tlsEnable"`
} `json:"mqtt"`
IncludeTopics []string `json:"includeTopics"`
ExcludeTopics []string `json:"excludeTopics"`
Syslog struct {
Enable string `json:"enable"`
Network string `json:"network"`
Server string `json:"server"`
Facility string `json:"facility"`
Severity string `json:"severity"`
Tag string `json:"tag"`
} `json:"syslog"`
}
var Config ConfigT
func LoadConfiguration() {
err := json.Unmarshal([]byte(os.Getenv("MA_CONF")), &Config)
if err != nil {
log.Fatalf("Unable to parse configuration: %s", err)
}
// Load password from environment variable only if not set in config
if Config.Mqtt.Password == "" {
Config.Mqtt.Password = os.Getenv("MQTT_PASSWORD")
}
}