MCPcopy
hub / github.com/mitchellh/mapstructure / ComposeDecodeHookFunc

Function ComposeDecodeHookFunc

decode_hooks.go:62–78  ·  view source on GitHub ↗

ComposeDecodeHookFunc creates a single DecodeHookFunc that automatically composes multiple DecodeHookFuncs. The composed funcs are called in order, with the result of the previous transformation.

(fs ...DecodeHookFunc)

Source from the content-addressed store, hash-verified

60// The composed funcs are called in order, with the result of the
61// previous transformation.
62func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
63 return func(f reflect.Value, t reflect.Value) (interface{}, error) {
64 var err error
65 data := f.Interface()
66
67 newFrom := f
68 for _, f1 := range fs {
69 data, err = DecodeHookExec(f1, newFrom, t)
70 if err != nil {
71 return nil, err
72 }
73 newFrom = reflect.ValueOf(data)
74 }
75
76 return data, nil
77 }
78}
79
80// OrComposeDecodeHookFunc executes all input hook functions until one of them returns no error. In that case its value is returned.
81// If all hooks return an error, OrComposeDecodeHookFunc returns an error concatenating all error messages.

Calls 1

DecodeHookExecFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…