numerus/pkg/htmx.go

32 lines
597 B
Go
Raw Permalink Normal View History

package pkg
import (
"encoding/json"
"net/http"
)
const (
HxLocation = "HX-Location"
HxRefresh = "HX-Refresh"
HxRequest = "HX-Request"
HxTrigger = "HX-Trigger"
HxTriggerAfterSettle = "HX-Trigger-After-Settle"
)
type HTMxLocation struct {
Path string `json:"path"`
Target string `json:"target"`
}
func IsHTMxRequest(r *http.Request) bool {
return r.Header.Get(HxRequest) == "true"
}
func MustMarshalHTMxLocation(location *HTMxLocation) string {
data, err := json.Marshal(location)
if err != nil {
panic(err)
}
return string(data)
}