在GOPATH模式下不能使用path @ version语法 [英] cannot use path@version syntax in GOPATH mode

查看:49
本文介绍了在GOPATH模式下不能使用path @ version语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> Set-Variable GO111MODULE -Value on
> go get golang.org/x/tools/gopls@latest
go: cannot use path@version syntax in GOPATH mode

到目前为止,我在学习Go方面经历了非常糟糕的经历.当我尝试在VS Code中重命名变量时,一切都开始了.这是故事.

So far I'm having a thoroughly horrible experience learning Go. It all started when I tried renaming a variable in VS Code. Here's the story.

  • 我正在学习Go,并且已经写了大约10行.
  • 我在Windows :-[上,这是一个障碍.
  • 我正在运行1.13版,我想开始时就好像我所知道的只是Go Modules.
  • 我没有设置GOPATH或GOROOT环境变量.
  • Go工具似乎在 c:\ Go 中.
  • 我下载了正在阅读的书的代码,并在VS Code中打开了它.
  • 我在VS Code中打开了 C:\ DATA \ go \ gopl.io \ ch1 \ fetchall \ main.go ,其中 c:\ DATA \ go 我坚持我的代码.
  • VS Code自动安装了很多Go工具来帮助我.
  • 我试图F2将 func main 中的变量重命名为对我来说更有意义的东西.
  • 我遇到了
  • I'm learning Go and have written about 10 lines, ever.
  • I'm on Windows :-[ which is proving a hurdle.
  • I'm running version 1.13 and I want to start as if Go Modules is all I've ever known.
  • I have neither a GOPATH or GOROOT environment variable set.
  • Go tooling seems to be in c:\Go.
  • I downloaded the code for a book I'm reading and opened it in VS Code.
  • I have C:\DATA\go\gopl.io\ch1\fetchall\main.go open in VS Code, c:\DATA\go is where I stick my code.
  • VS Code has auto installed a bunch of Go tools to help me.
  • I tried to F2 rename a variable in func main to something that made more sense to me.
  • I encountered
Rename failed: gorename: can't find package containing (path to your .go file)

据我的新手大脑所知,解决此错误的方法是,我需要更新一个名为 packages gopls 的程序包,该程序包是VS Code之类的东西.

The solution to this error, as far as my noob brain understands is that I need to update a package called packages or perhaps gopls which is the Language Server used by VS Code or something.

所以我运行了 c:\ DATA>去获得golang.org/x/tools/gopls@latest ,但出现一个错误,似乎与对语法的新支持有关,该语法用于指定版本和Go Modules是新的.

So I ran c:\DATA> go get golang.org/x/tools/gopls@latest but got an error that seemed to be something to do with new support for the syntax to specifying versions and Go Modules being new or something.

然后,我阅读了几个小时,发现这与某些 GO111MODULE 变量以及运行 go get 的文件夹有关.

I then read for hours more and found that this has something to do with some GO111MODULE variable and what folder I run go get from.

因此,我尝试设置该变量,但它似乎不起作用.

Hence I tried setting that variable but it doesn't seem to work.

请注意,我是从 c:\ DATA 运行这些命令的,而不是从本书示例 main.go 代码所在的位置运行这些命令的,因为我猜这是该语言服务器软件包不是用于该代码的,而是VS Code使用的东西,因此它应该是全局"的.以某种方式安装,在某处?但是我可能是错的.

Note I'm running these commands from c:\DATA rather than from where the book sample main.go code is, because I'm guessing that this Language Server package is not for that code, but is a thing that VS Code uses, and so its supposed to be "globally" installed somehow, somewhere? But I could be wrong.

如您所见,我对执行的操作并不感到困惑,好吧,它并不是很有趣.:(

As you can see, I haven't faintest idea what I'm doing and well, tbh, its not exactly fun :(

我确实将 GOPATH 设置为 c:\ DATA \ go ,但是在运行Powershell的VS Code终端中,当我运行 Get-Variable 未列出,但如果我随后运行 cmd 来输入普通的shell提示,则会设置它.奇怪

I do have a GOPATH set to c:\DATA\go but in the VS Code terminal which is PowerShell, when I run Get-Variable its not listed, but if I then run cmd to enter a normal shell prompt, it is set. Strange.

推荐答案

好的,问题是我的代码都不在 src 目录中.一旦将其全部移到 c:\ DATA \ go \ src 中,它就可以工作.

Okay the problem was that none of my code was in a src directory. Once I'd moved it all into c:\DATA\go\src it worked.

这篇关于在GOPATH模式下不能使用path @ version语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆