在本地计算机上运行第一个Go项目时出错 [英] Errors running first Go project on local machine
问题描述
我是Go的新手,所以请在这里忍受.我已经在本地计算机上安装了最新版本的Go,并从 https://github下载了源代码.com/rrrkren/topshot-sales 并将项目代码放在我的GOPATH中.当我在命令提示符下运行 go run go/main.go
时,出现这些错误
I'm new to Go so bear with me here. I've installed the latest version of Go on my local machine, downloaded the source code from https://github.com/rrrkren/topshot-sales and placed the project code in my GOPATH. When I run it go run go/main.go
in my command prompt, I get these errors
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文件位于当前目录中.我希望能够下载该项目并将其保存在本地计算机上,以便可以随时编辑源代码.感谢您的帮助.
even though the go.mod file is located in the current directory. I would like to be able to download this project and keep it on my local machine so I can edit the source code whenever I want. Any help is appreciated.
推荐答案
对于Go 1.16,您不需要使用 GOPATH
环境变量.
仅:
You should not need a GOPATH
environment variable with Go 1.16.
Only:
-
GO111MODULE = on
(在Go 1.17或1.18中不需要) -
GOPROXY = https://proxy.golang.org,直接
-
GOROOT = C:\ path \ to \ go
GO111MODULE=on
(won't be needed in Go 1.17 or 1.18)GOPROXY=https://proxy.golang.org,direct
GOROOT=C:\path\to\go
( GOROOT
,除非您已将Go安装在其默认文件夹中:%USERPROFILE%\ go
)
(GOROOT
unless you have installed Go in its default folder: %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
的错误,只有运行时执行错误.
No error about go.mod
, only a runtime execution error.
这篇关于在本地计算机上运行第一个Go项目时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!