github.com/fengyoulin/inspect@v0.2.1/types.go (about)

     1  package inspect
     2  
     3  import (
     4  	"reflect"
     5  	"unsafe"
     6  )
     7  
     8  var (
     9  	types map[string]reflect.Type
    10  )
    11  
    12  func init() {
    13  	types = make(map[string]reflect.Type)
    14  
    15  	typ := reflect.TypeOf(0)
    16  	face := (*iface)(unsafe.Pointer(&typ))
    17  
    18  	sections, offset := typelinks()
    19  	for i, offs := range offset {
    20  		rodata := sections[i]
    21  		for _, off := range offs {
    22  			face.data = resolveTypeOff(rodata, off)
    23  			if typ.Kind() == reflect.Ptr && len(typ.Elem().Name()) > 0 {
    24  				types[typ.String()] = typ
    25  				types[typ.Elem().String()] = typ.Elem()
    26  			}
    27  		}
    28  	}
    29  }