diff --git a/config/config.go b/config/config.go index 9732d5f..e02a4a5 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "os" + "strings" "github.com/joho/godotenv" "go.uber.org/zap" @@ -35,16 +36,25 @@ func NewConfig(logger *zap.Logger) *Config { logger.Warn("MQTT_PASSWORD is not set") } - topics := os.Getenv("MQTT_TOPICS") - if topics == "" { + topicsEnv := os.Getenv("MQTT_TOPICS") + var topics []string + if topicsEnv == "" { logger.Warn("MQTT_TOPICS is not set, defaulting to #") - topics = "#" + topics = []string{"#"} + } else { + parts := strings.Split(topicsEnv, ",") + for _, p := range parts { + t := strings.TrimSpace(p) + if t != "" { + topics = append(topics, t) + } + } } return &Config{ URI: uri, Username: username, Password: password, - Topics: []string{topics}, + Topics: topics, } }