Source File
type_map.go
Belonging Package
github.com/modern-go/reflect2
// +build !gccgopackage reflect2import ()// typelinks2 for 1.7 ~//go:linkname typelinks2 reflect.typelinksfunc typelinks2() ( []unsafe.Pointer, [][]int32)// initOnce guards initialization of types and packagesvar initOnce sync.Oncevar types map[string]reflect.Typevar packages map[string]map[string]reflect.Type// discoverTypes initializes types and packagesfunc discoverTypes() {types = make(map[string]reflect.Type)packages = make(map[string]map[string]reflect.Type)loadGoTypes()}func loadGoTypes() {var interface{} = reflect.TypeOf(0), := typelinks2()for , := range {:= []for , := range {(*emptyInterface)(unsafe.Pointer(&)).word = resolveTypeOff(unsafe.Pointer(), ):= .(reflect.Type)if .Kind() == reflect.Ptr && .Elem().Kind() == reflect.Struct {:= .Elem():= packages[.PkgPath()]if == nil {= map[string]reflect.Type{}packages[.PkgPath()] =}types[.String()] =[.Name()] =}}}}type emptyInterface struct {typ unsafe.Pointerword unsafe.Pointer}// TypeByName return the type by its name, just like Class.forName in javafunc ( string) Type {initOnce.Do(discoverTypes)return Type2(types[])}// TypeByPackageName return the type by its package and namefunc ( string, string) Type {initOnce.Do(discoverTypes):= packages[]if == nil {return nil}return Type2([])}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |