-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
- Loading branch information
1 parent
dc3fdab
commit 0e2c914
Showing
3 changed files
with
18 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,8 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
type MQTTProxyConfig struct { | ||
BrokerURL string `env:"PROXY_MQTT_ADDRESS" envDefault:"tcp://localhost:1883"` | ||
Password string `env:"PROXY_PROPLET_KEY" envDefault:""` | ||
PropletID string `env:"PROXY_PROPLET_ID" envDefault:""` | ||
ChannelID string `env:"PROXY_CHANNEL_ID" envDefault:""` | ||
} | ||
|
||
func (c *MQTTProxyConfig) Validate() error { | ||
if c.BrokerURL == "" { | ||
return errors.New("broker_url is required") | ||
} | ||
if _, err := url.Parse(c.BrokerURL); err != nil { | ||
return fmt.Errorf("broker_url is not a valid URL: %w", err) | ||
} | ||
if c.Password == "" { | ||
return errors.New("password is required") | ||
} | ||
if c.PropletID == "" { | ||
return errors.New("proplet_id is required") | ||
} | ||
if c.ChannelID == "" { | ||
return errors.New("channel_id is required") | ||
} | ||
|
||
return nil | ||
BrokerURL string `env:"PROXY_MQTT_ADDRESS" envDefault:"tcp://localhost:1883"` | ||
Password string `env:"PROXY_PROPLET_KEY,notEmpty" envDefault:""` | ||
PropletID string `env:"PROXY_PROPLET_ID,notEmpty" envDefault:""` | ||
ChannelID string `env:"PROXY_CHANNEL_ID,notEmpty" envDefault:""` | ||
} |