Files
ersteller/htmx/htmx.go
T

25 lines
656 B
Go

package htmx
import (
"encoding/json"
"git.gorlug.de/code/golang/ersteller-lib/ersteller"
"github.com/labstack/echo/v4"
)
type LocationRedirectParams struct {
Path string `json:"path"`
Target string `json:"target,omitempty"`
Swap string `json:"swap,omitempty"`
}
func LocationRedirect(c echo.Context, params LocationRedirectParams) error {
jsonData, err := json.Marshal(params)
if err != nil {
ersteller.Error("Failed to marshal LocationRedirectParams ", params, err)
return err
}
ersteller.Debug("LocationRedirectParams", params, "jsonData", string(jsonData))
c.Response().Header().Set("HX-Location", string(jsonData))
return nil
}