go 1.18.1 内置库中的主要包

main packages in go 1.18.1 built-in libraries

我正在尝试将项目的 golang 版本从 1.15 升级到 1.18.1。我在 go.mod 中更改了版本并执行了 go mod tidy 命令。

奇怪的是,我的主文件出现了以下错误,它本身有一个 main 函数:

'main' collides with name declared in this package

它发生在 net/httpsyscall 图书馆:

正如我检查的那样,警告是正确的,并且两个库中都有主要包。

我应该使用替代库还是应该更改导入它们的方式?

编辑 1:

这是一个 IDE 错误,我使用 Goland。

这是 reported recently(2022 年 4 月)(link 中文)

相关评论的翻译为:

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)。