summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-05-02 14:05:18 +0100
committerLibravatar GitHub <noreply@github.com>2022-05-02 15:05:18 +0200
commitb56dae8120d43b9acd3d3ed4d40100ffab7b972a (patch)
treed55d30589d8a8499ed3d5eecba163abc9fa78c27 /vendor/github.com/mitchellh/mapstructure/decode_hooks.go
parentadd extra indexes as a migration (#527) (diff)
downloadgotosocial-b56dae8120d43b9acd3d3ed4d40100ffab7b972a.tar.xz
[chore] Update all but bun libraries (#526)
* update all but bun libraries Signed-off-by: kim <grufwub@gmail.com> * remove my personal build script changes Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/github.com/mitchellh/mapstructure/decode_hooks.go')
-rw-r--r--vendor/github.com/mitchellh/mapstructure/decode_hooks.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/mapstructure/decode_hooks.go b/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
index 4d4bbc733..3a754ca72 100644
--- a/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
+++ b/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
@@ -77,6 +77,28 @@ func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
}
}
+// OrComposeDecodeHookFunc executes all input hook functions until one of them returns no error. In that case its value is returned.
+// If all hooks return an error, OrComposeDecodeHookFunc returns an error concatenating all error messages.
+func OrComposeDecodeHookFunc(ff ...DecodeHookFunc) DecodeHookFunc {
+ return func(a, b reflect.Value) (interface{}, error) {
+ var allErrs string
+ var out interface{}
+ var err error
+
+ for _, f := range ff {
+ out, err = DecodeHookExec(f, a, b)
+ if err != nil {
+ allErrs += err.Error() + "\n"
+ continue
+ }
+
+ return out, nil
+ }
+
+ return nil, errors.New(allErrs)
+ }
+}
+
// StringToSliceHookFunc returns a DecodeHookFunc that converts
// string to []string by splitting on the given sep.
func StringToSliceHookFunc(sep string) DecodeHookFunc {