handler: move mqttping into handler package; clean up main.go

This commit is contained in:
2025-12-28 16:40:00 +01:00
parent 915ebf5dbb
commit fc3350efcc
2 changed files with 26 additions and 13 deletions
+24
View File
@@ -0,0 +1,24 @@
package handler
import (
"net/http"
"os"
"time"
"github.com/gin-gonic/gin"
"git.piskot.si/SeminarM2/lambdaiot-core/internal/mqtt"
)
// MQTTPing publishes the current timestamp to the configured MQTT topic
func MQTTPing(c *gin.Context) {
ts := time.Now().Format(time.RFC3339)
topic := os.Getenv("MQTT_TOPIC")
if topic == "" {
topic = "lambdaiot"
}
if err := mqtt.PublishDefault(topic, []byte(ts)); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"timestamp": ts})
}