updated and tested till end of lesson 4
This commit is contained in:
@@ -70,7 +70,6 @@ func Load(args []string) (Config, error) {
|
||||
"TEST_MQTT5_MQTT_URL": "mqtt.url",
|
||||
"TEST_MQTT5_MQTT_CLIENT_ID": "mqtt.client_id",
|
||||
"TEST_MQTT5_MQTT_USERNAME": "mqtt.username",
|
||||
"TEST_MQTT5_MQTT_PASSWORD": "mqtt.password",
|
||||
"TEST_MQTT5_MQTT_DEVICE_ID": "mqtt.device_id",
|
||||
"TEST_MQTT5_APP_CONNECT_TIMEOUT": "app.connect_timeout",
|
||||
}
|
||||
@@ -122,10 +121,14 @@ func (c Config) Validate() error {
|
||||
if u.Hostname() != "127.0.0.1" && u.Hostname() != "localhost" {
|
||||
return fmt.Errorf("plaintext learning broker must be on loopback")
|
||||
}
|
||||
for _, value := range []string{c.MQTT.ClientID, c.MQTT.Username, c.MQTT.Password} {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return fmt.Errorf("client ID and credentials are required")
|
||||
}
|
||||
if strings.TrimSpace(c.MQTT.ClientID) == "" {
|
||||
return fmt.Errorf("mqtt.client_id is required")
|
||||
}
|
||||
if strings.TrimSpace(c.MQTT.Username) == "" {
|
||||
return fmt.Errorf("mqtt.username is required")
|
||||
}
|
||||
if strings.TrimSpace(c.MQTT.Password) == "" {
|
||||
return fmt.Errorf("mqtt.password is required in the TOML configuration")
|
||||
}
|
||||
if c.MQTT.DeviceID == "" || strings.ContainsAny(c.MQTT.DeviceID, "/+# \t\r\n") {
|
||||
return fmt.Errorf("device ID must be a nonempty single topic segment")
|
||||
|
||||
Reference in New Issue
Block a user