// primType dereferences an array to get the base type. func primType(typ types.Type) types.Type { for { typ = typ.Underlying() switch p := typ.(type) { case *types.Array: typ = p.Elem() default: return typ } } }
// isRecord returns if a type is a record. // The drillDown flag is used to determine if the function // should keep dereferencing arrays/pointers to get to the base // type or if it should only go down one level. func isRecord(typ types.Type, drillDown bool) bool { loop: for { typ = typ.Underlying() switch x := typ.(type) { case *types.Pointer: typ = x.Elem().Underlying() case *types.Array: typ = x.Elem().Underlying() default: break loop } if !drillDown { break } } _, ok := typ.Underlying().(*types.Record) return ok }
// isArray returns if a type is an array. func isArray(typ types.Type) bool { _, ok := typ.Underlying().(*types.Array) return ok }
// isPointer returns if a type is a pointer. func isPointer(typ types.Type) bool { _, ok := typ.Underlying().(*types.Pointer) return ok }