From 245f99d333baa6c3f675c81cf79ce9594eb1e943 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Wed, 18 Sep 2024 11:46:36 -0400 Subject: [PATCH] sketching out clients --- Makefile | 10 +++++++++- README.md | 4 +--- cmd/publisher/main.go | 7 +++++++ cmd/subscriber/main.go | 7 +++++++ common/common.go | 8 ++++---- 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 cmd/publisher/main.go create mode 100644 cmd/subscriber/main.go diff --git a/Makefile b/Makefile index 679b07a..f2b2ff7 100644 --- a/Makefile +++ b/Makefile @@ -20,4 +20,12 @@ stop-dev: install-dev-deps: python3 -m pip install pre-commit -.PHONEY: install-dev-dep \ No newline at end of file +.PHONEY: install-dev-dep + +run-pub: + go run ./cmd/publisher/main.go +.PHONEY: run-pub + +run-sub: + go run ./cmd/subscriber/main.go +.PHONEY: run-sub \ No newline at end of file diff --git a/README.md b/README.md index 6cb7d7e..2a00f3f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Learning MQTT with Golang by doing. This repo is a simple example of using a Golang application as a client (pub & sub) of an MQTT broker. - -8088, Management Center unsecured (opening the port on the internet is not recommended). 1883, Eclipse Mosquitto unsecured (opening the port on the internet is not recommended). ## Development @@ -39,7 +37,7 @@ make stop-dev - [Mosquitto Docs](https://mosquitto.org/man/mosquitto-8.html) - [Mosquitto TLS Tutorial](https://cedalo.com/blog/mqtt-tls-configuration-guide/) -- [Golang MQTT Tutorial]() +- [Golang MQTT Tutorial](https://www.emqx.com/en/blog/how-to-use-mqtt-in-golang) - [MQTT as a Service](https://cedalo.com/mqtt-broker-pro-mosquitto/) - [Using Wireshare for MQTT Analysis](https://cedalo.com/blog/wireshark-mqtt-guide/) - [Caddy as reverse proxy](https://github.com/caddyserver/caddy) diff --git a/cmd/publisher/main.go b/cmd/publisher/main.go new file mode 100644 index 0000000..33cb039 --- /dev/null +++ b/cmd/publisher/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("MQTT Publisher") +} diff --git a/cmd/subscriber/main.go b/cmd/subscriber/main.go new file mode 100644 index 0000000..fb1df88 --- /dev/null +++ b/cmd/subscriber/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("MQTT Subscriber") +} diff --git a/common/common.go b/common/common.go index 22a633c..7a73e89 100644 --- a/common/common.go +++ b/common/common.go @@ -3,11 +3,11 @@ package common import "os" // GetenvDefault retrieves an environment variable if set, or a provided default -func GetenvDefault(key string, d string) string { - val, ok := os.LookupEnv(key) - if ok { +func GetenvDefault(key string, defaultValue string) string { + val, exists := os.LookupEnv(key) + if exists { return val } else { - return d + return defaultValue } }