diff --git a/cmd/publisher/main.go b/cmd/publisher/main.go index 33cb039..223ce44 100644 --- a/cmd/publisher/main.go +++ b/cmd/publisher/main.go @@ -1,7 +1,13 @@ package main -import "fmt" +import ( + "flag" + "fmt" + + "git.runcible.io/learning/learn_mqtt_go/common" +) func main() { - fmt.Println("MQTT Publisher") + flag.Parse() + fmt.Printf("MQTT Host: %s\nMQTT Port: %s\n", *common.BrokerHost, *common.BrokerPort) } diff --git a/cmd/subscriber/main.go b/cmd/subscriber/main.go index fb1df88..223ce44 100644 --- a/cmd/subscriber/main.go +++ b/cmd/subscriber/main.go @@ -1,7 +1,13 @@ package main -import "fmt" +import ( + "flag" + "fmt" + + "git.runcible.io/learning/learn_mqtt_go/common" +) func main() { - fmt.Println("MQTT Subscriber") + flag.Parse() + fmt.Printf("MQTT Host: %s\nMQTT Port: %s\n", *common.BrokerHost, *common.BrokerPort) } diff --git a/common/common.go b/common/common.go index 7a73e89..15c3c84 100644 --- a/common/common.go +++ b/common/common.go @@ -1,6 +1,9 @@ package common -import "os" +import ( + "flag" + "os" +) // GetenvDefault retrieves an environment variable if set, or a provided default func GetenvDefault(key string, defaultValue string) string { @@ -11,3 +14,9 @@ func GetenvDefault(key string, defaultValue string) string { return defaultValue } } + +// For now just assume all values source from flags are strings +var ( + BrokerHost = flag.String("host", GetenvDefault("RUN_MQTT_HOST", "localhost"), "Hostname or IP address to an MQTT broker") + BrokerPort = flag.String("port", GetenvDefault("RUN_MQTT_PORT", "1883"), "Port to an MQTT broker") +)