feat: remove state message retrieval and associated SQLite storage

This commit is contained in:
2026-02-04 16:29:32 +01:00
parent 152d5b82cd
commit 014885db6c
5 changed files with 3 additions and 85 deletions

View File

@@ -8,7 +8,6 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"
@@ -20,7 +19,6 @@ import (
"git.piskot.si/SeminarM2/lambdaiot-core/internal/handler"
"git.piskot.si/SeminarM2/lambdaiot-core/internal/middleware"
mqttclient "git.piskot.si/SeminarM2/lambdaiot-core/internal/mqtt"
"git.piskot.si/SeminarM2/lambdaiot-core/internal/storage"
)
func main() {
@@ -52,26 +50,10 @@ func main() {
if cfg.Server.Port != 0 {
addr = fmt.Sprintf(":%d", cfg.Server.Port)
}
// connect to MQTT broker (best-effort)
var mq *mqttclient.Client
var checker *devicecheck.Checker
var checkCancel context.CancelFunc
// initialize sqlite for state messages
var stateDB *storage.DB
{
dbPath := os.Getenv("SQLITE_PATH")
if dbPath == "" {
dbPath = "state_messages.db"
}
dbInit, err := storage.Init(dbPath)
if err != nil {
log.Printf("warning: sqlite init failed: %v", err)
} else {
stateDB = dbInit
storage.SetDefault(stateDB)
}
}
if cfg.MQTT.Broker != "" {
mqc, err := mqttclient.Connect(cfg.MQTT)
if err != nil {
@@ -92,12 +74,6 @@ func main() {
if checker != nil {
checker.HandleMessage(p)
}
// if topic starts with state: -> store in sqlite
if strings.HasPrefix(t, "state:") {
if storage.Default != nil {
_ = storage.Default.InsertMessage(string(p), time.Now())
}
}
}
if err := mq.Subscribe(cfg.MQTT.Topic, handlerFn); err != nil {
log.Printf("warning: mqtt subscribe failed: %v", err)
@@ -149,7 +125,6 @@ func main() {
auth.Use(middleware.AuthMiddleware(cfg.Server.JWTSecret))
auth.GET("/protected", h.Protected)
auth.GET("/mqttping", h.MQTTPing)
auth.GET("/messages", handler.GetMessages)
auth.GET("/sensors", h.GetSensors)
auth.GET("/sensors/:id", h.GetSensor)
auth.POST("/sensors/:id/trigger", h.TriggerSensor)
@@ -202,9 +177,6 @@ func main() {
if checkCancel != nil {
checkCancel()
}
if stateDB != nil {
stateDB.Close()
}
log.Println("server exiting")
}