MCPcopy Index your code
hub / github.com/go-python/gopy / Embed

Function Embed

gopyh/handle.go:71–96  ·  view source on GitHub ↗

Embed returns the embedded struct (in first field only) of given type within given struct

(stru interface{}, embed reflect.Type)

Source from the content-addressed store, hash-verified

69
70// Embed returns the embedded struct (in first field only) of given type within given struct
71func Embed(stru interface{}, embed reflect.Type) interface{} {
72 if IfaceIsNil(stru) {
73 return nil
74 }
75 v := NonPtrValue(reflect.ValueOf(stru))
76 typ := v.Type()
77 if typ == embed {
78 return PtrValue(v).Interface()
79 }
80 if typ.NumField() == 0 {
81 return nil
82 }
83 f := typ.Field(0)
84 if f.Type.Kind() == reflect.Struct && f.Anonymous { // anon only avail on StructField fm typ
85 vf := v.Field(0)
86 vfpi := PtrValue(vf).Interface()
87 if f.Type == embed {
88 return vfpi
89 }
90 rv := Embed(vfpi, embed)
91 if rv != nil {
92 return rv
93 }
94 }
95 return nil
96}
97
98var (
99 trace = false

Callers

nothing calls this directly

Calls 4

IfaceIsNilFunction · 0.85
NonPtrValueFunction · 0.85
PtrValueFunction · 0.85
InterfaceMethod · 0.80

Tested by

no test coverage detected