rentease/internal/server/helper.go
Ruidy 584d81f7bd
Some checks failed
CI / checks (push) Has been cancelled
feat(i18n): add language toggle and localize views
2026-01-09 16:09:20 -04:00

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"
}