summaryrefslogtreecommitdiff
path: root/hh.go
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2025-04-10 21:33:41 +0200
committerMathias Magnusson <mathias@magnusson.space>2025-04-10 21:33:41 +0200
commit49bd3e0e0117768138f47f0c97accece15605025 (patch)
tree531306398969bf38fbaff946e5d67d122fa49c6b /hh.go
parentb9bf8a23c75db82e1aff8295a97dcfdf789735f3 (diff)
downloadhh-49bd3e0e0117768138f47f0c97accece15605025.tar.gz
extract value extracting and convertion to functions; support uuid
Diffstat (limited to 'hh.go')
-rw-r--r--hh.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/hh.go b/hh.go
index 16c25d2..84df871 100644
--- a/hh.go
+++ b/hh.go
@@ -1 +1,44 @@
package hh
+
+import (
+ "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)
+}