go: 找到了模块,但没有包含任何包。

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

go: module found but does not contain package

问题

我正在尝试安装Go语言的net包,但是遇到了"does not contain package error"的错误。

终端截图:

go: 找到了模块,但没有包含任何包。

我已经参考了https://stackoverflow.com/questions/62974985/go-module-latest-found-but-does-not-contain-package,但是其中的解决方案似乎都不适用于我。

我正在使用Go版本go1.18.5 linux/amd64

英文:

I am trying to install the net package for go but get "does not contain package error".

Terminal screenshot:

go: 找到了模块,但没有包含任何包。

I have consulted: https://stackoverflow.com/questions/62974985/go-module-latest-found-but-does-not-contain-package but none of the solutions seem to work for me.

I am using go version go1.18.5 linux/amd64

答案1

得分: 3

你必须在项目的根目录中使用go mod init来初始化你的模块。

对于本地代码库:

go mod init test

或者对于托管的代码库,例如github仓库:test,github用户:radiant

go mod init github.com/radiant/test

这将生成一个go.mod文件。

然后你可以通过以下方式获取所需的包:

go get golang.org/x/net
go mod tidy

然后导入并使用net包。

希望对你有所帮助。

英文:

You have to initialize your module with go mod init in the project root directory

For local codebase

go mod init test

OR for hosted codebase e.g. github repo: test, github user: radiant

go mod init github.com/radiant/test

It will produce a go.mod file.

Then you can get the required package as:

go get golang.org/x/net
go mod tidy

Then import and use the net packages.

Hope this helps.

答案2

得分: 0

go get -u golang.org/x/net

go install 用于安装可执行包。

英文:
go get -u golang.org/x/net

go install used for executable packages

huangapple
  • 本文由 发表于 2022年8月21日 21:59:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/73435155.html
匿名

发表评论

匿名网友

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

确定