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

Function typedDecodeHook

decode_hooks.go:16–36  ·  view source on GitHub ↗

typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns it into the proper DecodeHookFunc type, such as DecodeHookFuncType.

(h DecodeHookFunc)

Source from the content-addressed store, hash-verified

14// typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns
15// it into the proper DecodeHookFunc type, such as DecodeHookFuncType.
16func 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

Callers 1

DecodeHookExecFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…