2019-08-02 16:04
浏览 250


I am having issues using from vendor directory and I get the below error

cannot use &metadata.HeaderMD (type *"".MD) as type *"project1/vendor/".MD in argument to grpc.Header

I get the error though I am using the necessary version of the package which I copied from my gopath. But, when I delete the folder from vendor my project fetches the dependency from gopath and it works fine though the one gopath is a copy of when I have in vendor directory and every other library in vendor directory works fine except grpc.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufuhao8085 2019-08-03 08:04

    When you created project1/vendor/, it means that for packages under project1/..., an import of will be transparently remapped to the vendor version.

    Any packages outside of project1 will continue to import the non-vendored packages. While the vendored package might be a copy of the upstream, Go treats them as independent packages. So the types they contain are not equivalent.

    What has most likely happened is that one of your non-vendored dependencies imports the grpc package and uses its types in its public API. When you make use of that API from project1, you get the upstream type which can't be assigned to variables using the vendored types.

    There's two possible solutions to this problem:

    1. Vendor all of your dependencies that make use of what you've already vendored.

    2. If you're using Go >= 1.11, switch to the newer Go module build system. This will let you continue to control when you upgrade your dependencies without having the project1/vendor/... tree to confuse the type system.

    解决 无用
    打赏 举报

相关推荐 更多相似问题