英文:
main packages in go 1.18.1 built-in libraries
问题
我正在尝试将我的项目的golang版本从1.15
升级到1.18.1
。我在go.mod
文件中更改了版本,并执行了go mod tidy
命令。
奇怪的是,在我的主文件中出现了以下错误,该文件本身具有一个main
函数:
'main'与此包中声明的名称冲突
这发生在net/http
和syscall
库中:
-
net/http
在
/usr/local/go-1.18.1/src/net/http;/usr/local/go-1.18.1/src/net/http
中找到了多个包[http,main]。 -
syscall
在
/usr/local/go-1.18.1/src/syscall;/usr/local/go-1.18.1/src/syscall
中找到了多个包[syscall,main]。
我检查了警告,确实在这两个库中都有主包。
我应该使用替代库还是更改导入方式?
编辑1:
这是一个IDE错误,我使用的是Goland。
英文:
I am trying to upgrade my project's golang version from 1.15
to 1.18.1
. I changed the version in go.mod
and executed go mod tidy
command.
Weird thing, I got following error in my main file which has a main
function inside itself:
'main' collides with name declared in this package
It happens for net/http
and syscall
libraries:
-
net/http
Found several packages [http, main] in '/usr/local/go-1.18.1/src/net/http;/usr/local/go-1.18.1/src/net/http'
-
syscall
Found several packages [syscall, main] in '/usr/local/go-1.18.1/src/syscall;/usr/local/go-1.18.1/src/syscall'
As I checked the warning was correct and there were main packages in both libraries.
Should I use an alternative library or should I change the way I import them?
Edit 1:
This is an IDE error and I use Goland.
答案1
得分: 5
这是最近的报道(2022年4月)(中文链接)
相关评论的翻译如下:
> 上述错误的原因:您的Go语言版本已经升级,而IDE版本太旧无法支持。
>
> 例如,在我的情况下,Go已升级到1.18,而Goland没有升级。
因此,请确保您的IDE(GoLand或VSCode)已经完全更新(对于VSCode,请使用最新的gopls
)。
英文:
This was reported recently (Apr. 2022) (link in Chinese)
The translation of the relevant comment is:
> The reason for the above error: Your Go language version has been upgraded, and the IDE version is too old to support it.
>
> For example, in my case, Go was upgraded to 1.18, and Goland was not upgraded.
So make sure your IDE (GoLand or VSCode) is fully updated (with, for VSCode, the latest gopls
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论