From 39c6170ccab2977bbbaecdde2fdff772f39e2415 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Sat, 24 Jan 2026 01:57:33 +0100 Subject: allow returning values from handlers --- hh.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'hh.go') 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()) + } +} -- cgit v1.2.3