Go 1.18.1内置库中的主要包

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

main packages in go 1.18.1 built-in libraries

问题

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

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

'main'与此包中声明的名称冲突

这发生在net/httpsyscall库中:

  • 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 1.18.1内置库中的主要包

相关评论的翻译如下:

> 上述错误的原因:您的Go语言版本已经升级,而IDE版本太旧无法支持。
>
> 例如,在我的情况下,Go已升级到1.18,而Goland没有升级。

因此,请确保您的IDE(GoLand或VSCode)已经完全更新(对于VSCode,请使用最新的gopls)。

英文:

This was reported recently (Apr. 2022) (link in Chinese)

Go 1.18.1内置库中的主要包

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

huangapple
  • 本文由 发表于 2022年4月19日 07:18:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/71918001.html
匿名

发表评论

匿名网友

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

确定