GO 1.18.1内置库中的主要软件包

发布于 2025-01-22 15:01:12 字数 770 浏览 2 评论 0原文

我正在尝试将项目的Golang版本从1.15升级到1.18.1。我更改了go.mod的版本,并执行GO MOD TIDY命令。

很奇怪的是,我在主文件中遇到了以下错误,该文件内部具有main函数:

'main' collides with name declared in this package

net/http and syscall库>库发生。

  • net/http

     在'/usr/local/go-1.1.18.1/src/net/http ;/usr/local/go-1.18.1/src/src/net/http'中找到了几个软件包[http,main]
     
  • syscall

     在'/usr/local/go-1.1.18.1/src/syscall ;/usr/local/go-1.18.1/src/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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2025-01-29 15:01:12

最近报道了(2022年4月)

这 href =“ https://i.sstatic.net/hpfwc.png” rel =“ nofollow noreferrer”>

相关的翻译评论是:

上述错误的原因:您的GO语言版本已升级,IDE版本太旧了,无法支持它。

例如,就我而言,GO被升级到1.18,而Goland没有升级。

因此,请确保您的IDE(Goland或Vscode)已完全更新(对于vscode, gopls )。

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

https://img-blog.csdnimg.cn/d93c6e9fb3584a00a52bf1949da1ee02.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAS2lt6YeRNg==,size_20,color_FFFFFF,t_70,g_se,x_16

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文