github.com/wfusion/gofusion@v1.1.14/common/utils/inspect/init_go118.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package inspect 5 6 import ( 7 "reflect" 8 "runtime" 9 "unsafe" 10 ) 11 12 func enumerateTypes(cb func(reflect.Type) bool) { 13 t0 := reflect.TypeOf(struct{}{}) 14 sections, typeLinks := typelinks() 15 for i, typeLink := range typeLinks { 16 for _, link := range typeLink { 17 (*eface)(unsafe.Pointer(&t0)).data = resolveTypeOff(sections[i], link) 18 if t0.Kind() != reflect.Ptr || !supportTypes[t0.Elem().Kind()] { 19 continue 20 } 21 typ := t0.Elem() 22 if typ.PkgPath() == "" || typ.Name() == "" { 23 continue 24 } 25 if !cb(typ) { 26 return 27 } 28 } 29 } 30 } 31 32 func enumerateFuncs(cb func(*runtime.Func, uintptr) bool) { 33 for _, md := range activeModules() { 34 for _, tab := range md.ftab { 35 f := tab // should not take from &tab.entry because go syntax 36 absoluteAddr := textAddr(md, f.entry) 37 if fn := runtime.FuncForPC(absoluteAddr); fn != nil { 38 if !cb(fn, absoluteAddr) { 39 return 40 } 41 } 42 } 43 } 44 }