go/types:Config.Check找不到包

go/types:Config.Check找不到包,go,Go,我正在使用go/types包作为解析go源代码的工具。我的代码如下所示: packageName := "github.com/something/my-test-package" imported, err := build.Default.Import(packageName, ".", build.FindOnly) if err != nil { return nil, errors.Wrapf(err, "Error importing package %s", package

我正在使用
go/types
包作为解析go源代码的工具。我的代码如下所示:

packageName := "github.com/something/my-test-package"
imported, err := build.Default.Import(packageName, ".", build.FindOnly)
if err != nil {
    return nil, errors.Wrapf(err, "Error importing package %s", packageName)
}

packages, err := parser.ParseDir(fileSet, imported.Dir, nil, 0)
if err != nil {
    return nil, errors.Wrapf(err, "Error parsing package %s", packageName)
}

for _, astPkg := range packages {
    var files []*ast.File
    for _, file := range astPkg.Files {
        files = append(files, file)
    }

    info := &types.Info{
        Defs: make(map[*ast.Ident]types.Object),
    }

    conf := types.Config{
        Importer: importer.ForCompiler(fileSet, "source", nil),
    }

    _, err := conf.Check(packageName, fileSet, files, info)
    if err != nil {
        panic(err) // Panics here
    }
}
在上面的例子中,我从conf.Check中得到一个错误,即使我的代码构建得很好。错误是:

panic: /Users/home/Dev/my-test-package/bindings/bindings.go:6:2: could not import github.com/something/my-test-package/prototype (type-checking package "github.com/something/my-test-package/prototype" failed (/Users/home/Dev/my-test-package/prototype/basic.go:3:8: could not import <omitted> could not import github.com/golang/protobuf/ptypes/wrappers (type-checking package "github.com/golang/protobuf/ptypes/wrappers" failed (/Users/home/go/pkg/mod/github.com/golang/protobuf@v1.2.0/ptypes/wrappers/wrappers.pb.go:6:14: could not import github.com/golang/protobuf/proto (cannot find package "github.com/golang/protobuf/proto" in any of:
    /usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
    /Users/home/go/src/github.com/golang/protobuf/proto (from $GOPATH))))))))))))))))
panic:/Users/home/Dev/my-test-package/bindings/bindings.go:6:2:无法导入github.com/something/my-test-package/prototype(类型检查包“github.com/something/my-test-package/prototype”失败(/Users/home/Dev/my-test-package/prototype/basic.go:3:8:无法导入无法导入github.com/golang/protobuf/ptypes/wrappers)(类型检查包“github.com/golang/protobuf/ptypes/wrappers”失败(/Users/home/go/pkg/mod/github.com/golang)/protobuf@v1.2.0/ptypes/wrappers/wrappers.pb.go:6:14:无法导入github.com/golang/protobuf/proto(在以下任何一个文件中找不到包“github.com/golang/protobuf/proto”:
/usr/local/go/src/github.com/golang/protobuf/proto(来自$GOROOT)
/Users/home/go/src/github.com/golang/protobuf/proto(来自$GOPATH‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘
最终错误是:
无法导入github.com/golang/protobuf/proto


如果我从同一个包运行
go list-f'{.Dir}}'github.com/golang/protobuf/proto
,我会得到
/Users/home/go/pkg/mod/github.com/golang/protobuf@v1.3.1/proto
,因此该软件包显然可用。我,但我想我也会在这里发布,以防我做了一些明显错误的事情

这似乎是一个已知问题,或与已知问题相关:


有几个与这个问题有关。

不过我正在使用内置的
go/types
包。我想这应该适用于围棋模块。