package hh import ( "encoding/json" "net/http" "strconv" "github.com/google/uuid" ) func ExtractFromForm(r *http.Request, name string) (string, bool) { value := r.Form[name] if len(value) == 0 { return "", true } return value[0], false } func ExtractFromPath(r *http.Request, name string) (string, bool) { value := r.PathValue(name) if value == "" { return "", true } return value, false } func ExtractFromCookie(r *http.Request, name string) (string, bool) { value, err := r.Cookie(name) if err != nil { return "", true } return value.Value, false } func ConvertToInt(value string) (int, error) { return strconv.Atoi(value) } func ConvertToString(value string) (string, error) { return value, nil } 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()) } }