31 lines
507 B
Go
31 lines
507 B
Go
package pkg
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
HxLocation = "HX-Location"
|
|
HxRefresh = "HX-Refresh"
|
|
HxRequest = "HX-Request"
|
|
HxTrigger = "HX-Trigger"
|
|
)
|
|
|
|
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)
|
|
}
|