Abstract some of this out further, routing key passed as setup (seems to be tested...
authorjweigele <jweigele@local>
Tue, 6 Dec 2022 16:20:04 +0000 (08:20 -0800)
committerjweigele <jweigele@local>
Tue, 6 Dec 2022 16:20:04 +0000 (08:20 -0800)
helper/helper.go
wunder/main.go

index 858abc3f4fdb60d4138ec51db73247a97eb073c2..7b265a63955d90424a3b8af31bd1d4f9ec1c517b 100644 (file)
@@ -25,7 +25,6 @@ type RabbitConfig struct {
         Exchange   string
         Channel    *amqp.Channel
         RoutingKey string
-        Location   string
 }
 
 func failOnError(err error, msg string) {
@@ -34,7 +33,7 @@ func failOnError(err error, msg string) {
         }
 }
 
-func SetupRabbit(configFilename string) RabbitConfig {
+func SetupRabbit(configFilename string, routingKey string) RabbitConfig {
         configJSON, err := ioutil.ReadFile(configFilename)
         if err != nil {
                 failOnError(err, "oh no read")
@@ -73,8 +72,7 @@ func SetupRabbit(configFilename string) RabbitConfig {
         rabbit.Exchange = result["exchange"].(string)
         rabbit.Channel = rabbitChannel
         // constants
-        rabbit.RoutingKey = "temp"
-        rabbit.Location = "Outside (Wunderground)"
+        rabbit.RoutingKey = routingKey 
         return rabbit
 }
 
index e634851c402373a9d7276978566b411822eda3f5..8e96285970ad30dce3a5f5eb62978c51ef482091 100644 (file)
@@ -124,7 +124,8 @@ func sendTemp(tempValueF float64, tempValueC float64, rabbit helper.RabbitConfig
         sendObj := make(map[string]interface{})
         sendObj["celsius"] = tempValueC
         sendObj["fahrenheit"] = tempValueF
-        sendObj["location"] = rabbit.Location
+        // just a constant now
+        sendObj["location"] = "Outside (Wunderground)"
         utcNow := time.Now().UTC()
         dateString := timeutil.Strftime(&utcNow, "%Y-%m-%d %H:%M:%S")
         sendObj["date"] = dateString
@@ -134,7 +135,7 @@ func sendTemp(tempValueF float64, tempValueC float64, rabbit helper.RabbitConfig
 }
 
 func main() {
-       rabbit := helper.SetupRabbit(os.Args[1])
+       rabbit := helper.SetupRabbit(os.Args[1], "temp") // config file, routing key
        const weatherStation string = "KWASEATT2696"
        const sleepTime time.Duration = 30 * time.Second