summaryrefslogtreecommitdiff
path: root/hh.go
diff options
context:
space:
mode:
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)
+}