gpt4 book ai didi

go - 在本地计算机上运行第一个Go项目时出错

转载 作者:行者123 更新时间:2023-12-03 15:53:44 25 4
gpt4 key购买 nike

我是Go的新手,所以请在这里与我联系。我已经在本地计算机上安装了最新版本的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,direct
  • GOROOT=C:\path\to\go

  • ( GOROOT,除非您已在其默认文件夹 %USERPROFILE%\go中安装了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 - 在本地计算机上运行第一个Go项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66740187/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com