在本地机器上运行第一个Go项目时出错
我是 Go 的新手,所以请耐心等待。我已经在本地机器上安装了最新版本的 Go,从https://github.com/rrrkren/topshot-sales下载了源代码并将项目代码放在我的 GOPATH 中。当我go run go/main.go在命令提示符下运行它时,出现这些错误
gomain.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'
gomain.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'
gomain.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 文件位于当前目录中。我希望能够下载这个项目并将它保存在我的本地机器上,这样我就可以随时编辑源代码。任何帮助表示赞赏。
回答
这对我有用。
步骤 1. 如果您怀疑是否正确配置了任何以前的 golang 版本,请删除它。
第2步 。安装新的 golang 版本。从这里下载二进制版本(golang)Golang Binay 下载
注意 - 为了删除和安装新的 golang 版本,您可以使用这些步骤 - Golang 删除和安装,它们对我有用。另外我目前使用的版本是 1.16.3
步骤 3. 完成 step1 和 step2 后,在终端中运行以下命令-
去 env -w GO111MODULE=auto
这应该可以。
回答
GOPATHGo 1.16不需要环境变量。
仅有的:
GO111MODULE=on(在 Go 1.17 或 1.18 中不需要)GOPROXY=https://proxy.golang.org,directGOROOT=C:pathtogo
(GOROOT除非你在它的默认文件夹中安装转到:%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:gittopshot-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,只有运行时执行错误。