diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2025-04-10 21:33:41 +0200 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2025-04-10 21:33:41 +0200 |
commit | 49bd3e0e0117768138f47f0c97accece15605025 (patch) | |
tree | 531306398969bf38fbaff946e5d67d122fa49c6b /hh.go | |
parent | b9bf8a23c75db82e1aff8295a97dcfdf789735f3 (diff) | |
download | hh-49bd3e0e0117768138f47f0c97accece15605025.tar.gz |
extract value extracting and convertion to functions; support uuid
Diffstat (limited to 'hh.go')
-rw-r--r-- | hh.go | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -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) +} |