VSCode Go扩展加载带有私有存储库依赖项的工作区时出错。

huangapple go评论157阅读模式
英文:

VSCode Go extension Error loading workspace with private repository dependency

问题

一切都正常工作,直到我添加了一个私有仓库的依赖。我注意到自动完成停止工作,并且在 vscode 中有一个错误通知:

加载工作区时出错:err: 退出状态 1: stderr: go:
bitbucket.org/my-group/my-private-repo@v0.0.0-20210512194559-2c29669c4ecc: 
读取 https://api.bitbucket.org/2.0/repositories/my-group/my-private-repo?fields=scm 时出错: 
403 Forbidden 服务器响应:拒绝访问。您必须具有写入或管理员访问权限。 
go: bitbucket.org/my-group/my-private-repo@v0.0.0-20210512194559-2c29669c4ecc: 
读取 https://api.bitbucket.org/2.0/repositories/my-group/my-private-repo?fields=scm 时出错: 
403 Forbidden 服务器响应:拒绝访问。您必须具有写入或管理员访问权限。 
: packages.Load 错误

看起来 go 扩展正在尝试访问我的私有仓库:

  1. 为什么代码竞赛需要访问我的私有仓库?
  2. 如果有必要,我如何向 go 扩展提供我的 SSH 密钥?
  3. 其他解决方法?
英文:

Everything was working fine until I added a dependency of a private repository. I noticed that autocomplete stopped working and there was an error notification by vscode:

Error loading workspace: err: exit status 1: stderr: go:
bitbucket.org/my-group/my-private-repo@v0.0.0-20210512194559-2c29669c4ecc: 
reading https://api.bitbucket.org/2.0/repositories/my-group/my-private-repo?fields=scm: 
403 Forbidden server response: Access denied. You must have write or admin access. 
go: bitbucket.org/my-group/my-private-repo@v0.0.0-20210512194559-2c29669c4ecc: 
reading https://api.bitbucket.org/2.0/repositories/my-group/my-private-repo?fields=scm: 
403 Forbidden server response: Access denied. You must have write or admin access. 
: packages.Load error

It seems like the go extension is trying to access my private repo:

  1. Why is this necessary for code competition to be able to work?
  2. If it is necessary, how do I provide my SSH-key to the go extension?
  3. Other workaround?

答案1

得分: 1

  1. 它试图获取您的依赖项的源代码,以便为您生成实际的建议。它希望以go模块的方式加载源代码,我猜您的依赖项位于GOPATH中。您希望它能够优雅地处理连接错误,并仍然为可以访问的代码提供补全建议,所以这可能是一个bug,请考虑在GitHub上创建一个问题(我不知道是哪个项目)。
  2. 在这种情况下,是的,通过进行以下修复,您将能够使用go mod来管理私有依赖项,而不是手动管理依赖项的“旧方式”。Go模块默认使用Git,您可以通过将以下内容添加到全局git配置文件中,指示git始终使用SSH而不是HTTPS:
insteadOf = https://bitbucket.org/

您的私钥应该会自动使用,假设您不需要任何特殊配置来进行普通的git over ssh操作。

  1. Go模块支持通过vendor目录包含依赖项。如果您将依赖项放在那里,代码补全应该使用它而不是尝试下载它。但我无法确认这一点,因为我从未尝试过。
英文:
  1. It attempts to get the sources for your dependency so it can generate the actual suggestions for your. It wants to load the source go module style and I am guessing you have your dependency located in the GOPATH. You would hope it would gracefully handle the connection errors and still provide completions for the code it can access, so maybe this is a bug, consider creating an issue on github(I don't know which project).
  2. In this case it is, also by doing the following fix you will be able to use go mod for private dependencies as well instead of having to manually manage dependencies the "old fashion" way. Go modules uses Git by default, you can instruct git to always use SSH instead of HTTPS by adding the following to your global git config file:
insteadOf = https://bitbucket.org/

Your private key should be used automatically, assuming you don't require any special config for normal git over ssh operations.

  1. Go modules supports inclusion of dependencies via the vendor directory. If you place your dependency in there the code completion should use it instead of trying to download it. But I can't confirm this, have never tried it

huangapple
  • 本文由 发表于 2021年11月9日 19:25:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/69897276.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定