[英]go: module found but does not contain package
I am trying to install the net package for go but get "does not contain package error".我正在尝试为 go 安装网络 package 但得到“不包含 package 错误”。
Terminal screenshot:终端截图:
I have consulted: go module @latest found but does not contain package but none of the solutions seem to work for me.我已经咨询过: go 模块 @latest found 但不包含 package但似乎没有一个解决方案适合我。
I am using go version go1.18.5 linux/amd64
我正在使用 go 版本
go1.18.5 linux/amd64
go get -u golang.org/x/net
go install used for executable packages go 安装用于可执行包
You have to initialize your module with go mod init
in the project root directory您必须在项目根目录中使用
go mod init
初始化您的模块
For local codebase对于本地代码库
go mod init test
OR for hosted codebase eg github repo: test , github user: radiant或用于托管代码库,例如 github 存储库:测试,github 用户:辐射
go mod init github.com/radiant/test
It will produce a go.mod
file.它将生成一个
go.mod
文件。
Then you can get the required package as:然后您可以获得所需的 package 为:
go get golang.org/x/net
go mod tidy
Then import and use the net packages.然后导入并使用网络包。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.