numerus/pkg/htmx.go

24 lines
390 B
Go

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