refactor(db): add flag to run without MQTT part
Use for local test for developement Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"gateway/rest"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -92,18 +93,21 @@ func influxConnection() *influx.InfluxGateway {
|
||||
// @BasePath /api/v1
|
||||
// @securityDefinitions.basic BasicAuth
|
||||
func main() {
|
||||
noMqtt := slices.Contains(os.Args[1:], "--no-mqtt")
|
||||
|
||||
// Load mapping configuration (reloaded dynamically on each access)
|
||||
mappingPath := getEnv("MAPPING_CONFIG_PATH", "mapping.json")
|
||||
mapping := NewDynamicMapping(mappingPath)
|
||||
|
||||
mqttGateway := mqttConnection()
|
||||
defer mqttGateway.Disconnect()
|
||||
|
||||
influxGateway := influxConnection()
|
||||
defer influxGateway.Close()
|
||||
|
||||
measurementName := getEnv("CAMPUS", "provence")
|
||||
|
||||
if !noMqtt {
|
||||
mqttGateway := mqttConnection()
|
||||
defer mqttGateway.Disconnect()
|
||||
|
||||
// Create measurement for provence topic
|
||||
provenceMeasurement := point.CreateMeasurement[ProvenceData](measurementName)
|
||||
// The incoming MQTT topic structure is: <gateway_id>/<node_id>/update
|
||||
@@ -171,6 +175,9 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
log.Println("[Main] MQTT disabled (--no-mqtt flag set)")
|
||||
}
|
||||
|
||||
// Initialize and start REST Gateway
|
||||
restUsername := getEnv("REST_USERNAME", "user")
|
||||
|
||||
Reference in New Issue
Block a user