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)
| 60 | // The composed funcs are called in order, with the result of the |
| 61 | // previous transformation. |
| 62 | func 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. |
searching dependent graphs…