mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
34 lines
719 B
Go
34 lines
719 B
Go
package server
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
func renderTempl(w http.ResponseWriter, r *http.Request, status int, t templ.Component) error {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
w.WriteHeader(status)
|
|
|
|
if err := t.Render(r.Context(), w); err != nil {
|
|
log.Printf("failed to render response template %s", err)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func hxRedirect(w http.ResponseWriter, statusCode int, url string) error {
|
|
w.Header().Add("HX-Redirect", url)
|
|
w.WriteHeader(statusCode)
|
|
return nil
|
|
}
|
|
|
|
func hxRequest(r *http.Request) bool {
|
|
return r.Header.Get("Hx-Request") == "true"
|
|
}
|
|
|
|
func hxBoosted(r *http.Request) bool {
|
|
return r.Header.Get("Hx-Boosted") == "true"
|
|
}
|