From: jweigele Date: Tue, 6 Dec 2022 16:20:04 +0000 (-0800) Subject: Abstract some of this out further, routing key passed as setup (seems to be tested... X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=549fb4e50ed2ce5d96d961811a16e6488c2382b9;p=rabbit_go Abstract some of this out further, routing key passed as setup (seems to be tested working) --- diff --git a/helper/helper.go b/helper/helper.go index 858abc3..7b265a6 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -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 } diff --git a/wunder/main.go b/wunder/main.go index e634851..8e96285 100644 --- a/wunder/main.go +++ b/wunder/main.go @@ -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