我正在尝试将项目的 golang 版本从 1.15
升级到 1.18.1
。我更改了 go.mod
中的版本并执行了 go mod tidy
命令。
奇怪的是,我的主文件中有以下错误,它本身有一个 main
函数:
'main' collides with name declared in this package
它发生在 net/http
和 syscall
库中:
网络/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'
系统调用
Found several packages [syscall, main] in '/usr/local/go-1.18.1/src/syscall;/usr/local/go-1.18.1/src/syscall'
正如我检查的那样,警告是正确的,并且两个库中都有主要包。
我应该使用替代库还是应该更改导入它们的方式?
编辑 1:
这是一个 IDE 错误,我使用的是 Goland。
最佳答案
这是 reported recently (2022 年 4 月)(中文链接)
相关评论的译文是:
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.
因此请确保您的 IDE(GoLand 或 VSCode)已完全更新(对于 VSCode,使用 latest gopls
)。
关于go - go 1.18.1 内置库中的主要包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71918001/