typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns it into the proper DecodeHookFunc type, such as DecodeHookFuncType.
(h DecodeHookFunc)
| 14 | // typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns |
| 15 | // it into the proper DecodeHookFunc type, such as DecodeHookFuncType. |
| 16 | func typedDecodeHook(h DecodeHookFunc) DecodeHookFunc { |
| 17 | // Create variables here so we can reference them with the reflect pkg |
| 18 | var f1 DecodeHookFuncType |
| 19 | var f2 DecodeHookFuncKind |
| 20 | var f3 DecodeHookFuncValue |
| 21 | |
| 22 | // Fill in the variables into this interface and the rest is done |
| 23 | // automatically using the reflect package. |
| 24 | potential := []interface{}{f1, f2, f3} |
| 25 | |
| 26 | v := reflect.ValueOf(h) |
| 27 | vt := v.Type() |
| 28 | for _, raw := range potential { |
| 29 | pt := reflect.ValueOf(raw).Type() |
| 30 | if vt.ConvertibleTo(pt) { |
| 31 | return v.Convert(pt).Interface() |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | // DecodeHookExec executes the given decode hook. This should be used |
| 39 | // since it'll naturally degrade to the older backwards compatible DecodeHookFunc |
no outgoing calls
no test coverage detected
searching dependent graphs…