summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/basic.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/basic.go b/examples/basic.go
index d8ad6d7..5986e7e 100644
--- a/examples/basic.go
+++ b/examples/basic.go
@@ -1,9 +1,11 @@
package main
import (
+ "errors"
"log/slog"
"net/http"
+ "git.0m.nu/hh"
"github.com/google/uuid"
)
@@ -26,6 +28,29 @@ func adminUsersForm(r struct {
slog.Info("get admin users form", "search", r.search, "offset", r.offset, "next-url", r.nextURL)
}
+//hh:route GET /return-err
+func returnErr(r struct{ raw *http.Request }) error {
+ _ = r
+ return errors.New("whoops")
+}
+
+//hh:route GET /return-value
+func returnValue(r struct{ raw *http.Request }) hh.JSONValue {
+ _ = r
+ return hh.JSON(map[string]any{"key": []string{"value", "s"}})
+}
+
+//hh:route GET /return-both/{which}
+func returnBoth(r struct {
+ which string `hh:"path"`
+}) (hh.JSONValue, error) {
+ if r.which == "error" {
+ return hh.JSON(nil), errors.New("whoops")
+ } else {
+ return hh.JSON(map[string]any{"key": []string{"value", "s"}}), nil
+ }
+}
+
func main() {
hhMountRoutes(nil)
slog.Error("Error listening", "error", http.ListenAndServe(":http", nil))