Errything changing

This commit is contained in:
2024-03-27 14:52:28 -06:00
parent 3ba730043f
commit 0b8b895c21
14 changed files with 103 additions and 117 deletions

37
api/tools.sendsse.go Normal file
View File

@ -0,0 +1,37 @@
package api
import (
"net/http"
"atri.dad/lib"
"atri.dad/lib/pubsub"
"github.com/labstack/echo/v4"
)
func SSEDemoSend(c echo.Context, pubSub pubsub.PubSub) error {
channel := c.QueryParam("channel")
if channel == "" {
channel = "default"
}
// Get message from query parameters, form value, or request body
message := c.QueryParam("message")
if message == "" {
message = c.FormValue("message")
if message == "" {
var body map[string]string
if err := c.Bind(&body); err != nil {
return err
}
message = body["message"]
}
}
if message == "" {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "message parameter is required"})
}
lib.SendSSE(c.Request().Context(), pubSub, "default", message)
return c.JSON(http.StatusOK, map[string]string{"status": "message sent"})
}