package main import ( "fmt" "io/ioutil" "log" "os" "strings" ) func failOnError(err error, msg string) { if err != nil { log.Panicf("%s: %s", msg, err) } } func main() { amqpConn := AMQPConnection{} amqpConn.Init() err := amqpConn.Connect() defer amqpConn.Close() failOnError(err, "Failed to connect to RabbitMQ") // read token from /token/read_write_token.txt file token_file := "/tokens/read_write.txt" token_bytes, err := ioutil.ReadFile(token_file) failOnError(err, "Failed to read token file") influx_token := strings.TrimSpace(string(token_bytes)) fmt.Println("InfluxDB token:") fmt.Println(strings.TrimSpace(string(influx_token))) influx := InfluxWriter{} influx.Init( os.Getenv("INFLUX_URL"), strings.TrimSpace(string(influx_token)), os.Getenv("INFLUX_ORG"), os.Getenv("INFLUX_BUCKET"), ) // create exchange err = amqpConn.channel.ExchangeDeclare( "amq.topic", // name "topic", // type true, // durable false, // auto-deleted false, // internal false, // no-wait nil, // arguments ) failOnError(err, "Failed to declare an exchange") var forever chan struct{} shellPipe := new(Piper) shellPipe.Start(&influx, &amqpConn, "shelly", "shellies.#", ShellyConverter) tasmotaPipe := new(Piper) tasmotaPipe.Start(&influx, &amqpConn, "tasmota", "tele.#.SENSOR", TasmotaConverter) log.Printf(" [*] Waiting for logs. To exit press CTRL+C") <-forever }