github.com/goplus/reflectx@v1.2.2/context.go (about) 1 package reflectx 2 3 import ( 4 "fmt" 5 "reflect" 6 7 "github.com/goplus/reflectx/abi" 8 ) 9 10 var ( 11 // disable unable allocate warning 12 DisableAllocateWarning bool 13 ) 14 15 var Default *Context = NewContext() 16 17 type Context struct { 18 embedLookupCache map[reflect.Type]reflect.Type 19 structLookupCache map[string][]reflect.Type 20 interfceLookupCache map[string]reflect.Type 21 methodIndexList map[abi.MethodProvider][]int 22 nAllocateError int 23 } 24 25 func NewContext() *Context { 26 ctx := &Context{} 27 ctx.embedLookupCache = make(map[reflect.Type]reflect.Type) 28 ctx.structLookupCache = make(map[string][]reflect.Type) 29 ctx.interfceLookupCache = make(map[string]reflect.Type) 30 ctx.methodIndexList = make(map[abi.MethodProvider][]int) 31 return ctx 32 } 33 34 type AllocError struct { 35 Typ reflect.Type 36 Cap int 37 Req int 38 } 39 40 func (p *AllocError) Error() string { 41 return fmt.Sprintf("cannot alloc method %q, cap:%v req:%v", 42 p.Typ, p.Cap, p.Req) 43 }