aboutsummaryrefslogtreecommitdiff
path: root/kcore/http.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-12-24 19:20:25 +0100
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-12-24 19:20:25 +0100
commitc1b78bf43b1f20706c787061d7238e7acd8b5b2d (patch)
tree936dba9ae768c0fedf4456db4d0392826072ccff /kcore/http.go
parent6d05a64a0a40df152b218d76c9247c1aa743c879 (diff)
Implements Must function and enhances Unauthorized handlerv0.7.0
Adds the Must function for error handling, simplifying code by allowing panic on errors. Improves the Unauthorized handler to ensure proper error reporting when writing responses.
Diffstat (limited to 'kcore/http.go')
-rw-r--r--kcore/http.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/kcore/http.go b/kcore/http.go
index e5d218b..f1a2b1a 100644
--- a/kcore/http.go
+++ b/kcore/http.go
@@ -26,3 +26,11 @@ func RenderPage(ctx context.Context, page templ.Component, w http.ResponseWriter
_, err = buf.WriteTo(w)
Expect(err, "error writing page to response writer")
}
+
+func Unauthorized(w http.ResponseWriter, err error) {
+ w.WriteHeader(http.StatusUnauthorized)
+ if err != nil {
+ _, err = w.Write([]byte(err.Error()))
+ Expect(err, "error writing response")
+ }
+}