func lookupType(node ast.Node, info *types.Info) (types.Object, *types.Selection, error) { switch n := node.(type) { case *ast.Ident: return info.ObjectOf(n), nil, nil case *ast.ImportSpec: return info.ObjectOf(n.Name), nil, nil case *ast.SelectorExpr: if sel, ok := info.Selections[n]; ok { return sel.Obj(), sel, nil } return info.ObjectOf(n.Sel), nil, nil case *ast.StructType: return nil, nil, fmt.Errorf("unexpected struct: %#v", node) default: return nil, nil, fmt.Errorf("unexpected type: %#v", node) } return nil, nil, errors.New("object not found...") }