aboutsummaryrefslogtreecommitdiff
path: root/kcore
diff options
context:
space:
mode:
Diffstat (limited to 'kcore')
-rw-r--r--kcore/error.go7
-rw-r--r--kcore/http.go8
2 files changed, 15 insertions, 0 deletions
diff --git a/kcore/error.go b/kcore/error.go
index fad5f3d..3e4ee1f 100644
--- a/kcore/error.go
+++ b/kcore/error.go
@@ -29,3 +29,10 @@ func Assert(cond bool, msg string) {
panic(err)
}
}
+
+func Must[T any](val T, err error) T {
+ if err != nil {
+ panic(err)
+ }
+ return val
+}
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")
+ }
+}