在本地机器上运行第一个 Go 项目时出错
时间:2023-04-13
浏览:331
作者:佚名
欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《在本地机器上运行第一个 Go 项目时出错》,这篇文章主要讲到golang等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!
问题内容
我在本地机器上安装了最新版本的 Go,从https://github.com/rrrkren/topshot- sales下载了源代码,并将项目代码放在我的 GOPATH 中。
当我go run go/main.go在命令提示符下运行它时,出现这些错误
go\main.go:8:2: no required module provides package github.com/onflow/flow-go-sdk/client: go.mod file not found in current directory or any parent directory; see 'go help modules' go\main.go:6:2: no required module provides package github.com/rrrkren/topshot-sales/topshot: go.mod file not found in current directory or any parent directory; see 'go help modules' go\main.go:9:2: no required module provides package google.golang.org/grpc: go.mod file not found in current directory or any parent directory; see 'go help modules'
即使 go.mod 文件位于当前目录中。我希望能够下载这个项目并将其保存在我的本地机器上,这样我就可以随时编辑源代码。我怎样才能做到这一点?
正确答案
Go 1.16不需要GOPATH环境变量。仅有的:
GO111MODULE=on(在 Go 1.17 或 1.18 中不需要)GOPROXY=https://proxy.golang.org,directGOROOT=C:\path\to\go
(GOROOT除非您已将 Go 安装在其默认文件夹中%USERPROFILE%\go:)
我试过了:
D:\git> git clone https://github.com/rrrkren/topshot-sales
Cloning into 'topshot-sales'...
remote: Enumerating objects: 25, done.
remote: Counting objects: 100% (25/25), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 25 (delta 9), reused 21 (delta 6), pack-reused 0
Receiving objects: 100% (25/25), 16.95 KiB | 5.65 MiB/s, done.
Resolving deltas: 100% (9/9), done.
D:\git> cd topshot-sales
D:\git\topshot-sales> go run main.go
go: downloading github.com/onflow/flow-go-sdk v0.10.0
...
go: downloading gopkg.in/yaml.v2 v2.2.5
panic: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 35.193.214.129:9000: i/o timeout"
goroutine 1 [running]:
main.handleErr(...)
D:/git/topshot-sales/main.go:14
main.main()
D:/git/topshot-sales/main.go:23 +0x805
exit status 2
没有关于 的错误go.mod,只有运行时执行错误。
终于介绍完啦!小伙伴们,这篇关于《在本地机器上运行第一个 Go 项目时出错》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.29
11.29
11.29
11.29
11.29
11.29
热门专题
