summaryrefslogtreecommitdiff
path: root/vendor/github.com/go-playground/form/v4/util.go
diff options
context:
space:
mode:
authorLibravatar zowhoey <11893985+zowhoey@users.noreply.github.com>2023-03-06 09:30:19 +0000
committerLibravatar GitHub <noreply@github.com>2023-03-06 10:30:19 +0100
commitf518f649f800e52d32fe53580c528ffa042f7154 (patch)
treec14bb8b513008d1c1e7bab0908cfc99fe18f1507 /vendor/github.com/go-playground/form/v4/util.go
parent[chore]: Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.1 (#1595) (diff)
downloadgotosocial-f518f649f800e52d32fe53580c528ffa042f7154.tar.xz
[feature] Add support for profile fields (#1483)
* Add go-playground/form pkg * [feature] Add support for profile fields * Add field attributes test * Validate profile fields form * Add profile field validation tests * Add Field Attributes definition to swagger --------- Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/go-playground/form/v4/util.go')
-rw-r--r--vendor/github.com/go-playground/form/v4/util.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/go-playground/form/v4/util.go b/vendor/github.com/go-playground/form/v4/util.go
new file mode 100644
index 000000000..02c86af72
--- /dev/null
+++ b/vendor/github.com/go-playground/form/v4/util.go
@@ -0,0 +1,62 @@
+package form
+
+import (
+ "reflect"
+ "strconv"
+)
+
+// ExtractType gets the actual underlying type of field value.
+// it is exposed for use within you Custom Functions
+func ExtractType(current reflect.Value) (reflect.Value, reflect.Kind) {
+
+ switch current.Kind() {
+ case reflect.Ptr:
+
+ if current.IsNil() {
+ return current, reflect.Ptr
+ }
+
+ return ExtractType(current.Elem())
+
+ case reflect.Interface:
+
+ if current.IsNil() {
+ return current, reflect.Interface
+ }
+
+ return ExtractType(current.Elem())
+
+ default:
+ return current, current.Kind()
+ }
+}
+
+func parseBool(str string) (bool, error) {
+
+ switch str {
+ case "1", "t", "T", "true", "TRUE", "True", "on", "yes", "ok":
+ return true, nil
+ case "", "0", "f", "F", "false", "FALSE", "False", "off", "no":
+ return false, nil
+ }
+
+ // strconv.NumError mimicing exactly the strconv.ParseBool(..) error and type
+ // to ensure compatibility with std library and beyond.
+ return false, &strconv.NumError{Func: "ParseBool", Num: str, Err: strconv.ErrSyntax}
+}
+
+// hasValue determines if a reflect.Value is it's default value
+func hasValue(field reflect.Value) bool {
+ switch field.Kind() {
+ case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
+ return !field.IsNil()
+ default:
+ if !field.IsValid() {
+ return false
+ }
+ if !field.Type().Comparable() {
+ return true
+ }
+ return field.Interface() != reflect.Zero(field.Type()).Interface()
+ }
+}