summaryrefslogtreecommitdiff
path: root/hh.go
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2026-01-24 01:57:33 +0100
committerMathias Magnusson <mathias@magnusson.space>2026-01-24 01:57:33 +0100
commit39c6170ccab2977bbbaecdde2fdff772f39e2415 (patch)
tree97d1d360e8ce62517a573380c0c03362915e55e8 /hh.go
parent1fe804770391a644e23eea7c22e0868e3dfb4d2e (diff)
downloadhh-39c6170ccab2977bbbaecdde2fdff772f39e2415.tar.gz
allow returning values from handlersHEADmain
Diffstat (limited to 'hh.go')
-rw-r--r--hh.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/hh.go b/hh.go
index 84df871..a8b7cd4 100644
--- a/hh.go
+++ b/hh.go
@@ -1,6 +1,7 @@
package hh
import (
+ "encoding/json"
"net/http"
"strconv"
@@ -42,3 +43,19 @@ func ConvertToString(value string) (string, error) {
func ConvertToUuidUUID(value string) (uuid.UUID, error) {
return uuid.Parse(value)
}
+
+type ToResponse interface {
+ Respond(w http.ResponseWriter, r *http.Request)
+}
+
+func JSON(a any) JSONValue {
+ return JSONValue{a}
+}
+
+type JSONValue struct{ any }
+
+func (j JSONValue) Respond(w http.ResponseWriter, r *http.Request) {
+ if err := json.NewEncoder(w).Encode(j); err != nil {
+ panic("todo: internal server error: " + err.Error())
+ }
+}