Errors running the first Go project on the local machine

Issue

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'

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. How can I do that?

Solution

You should not need a GOPATH environment variable with Go 1.16.
Only:

  • 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 unless you have installed Go in its default folder: %USERPROFILE%\go)

I tried:

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

No error about go.mod, only a runtime execution error.

Answered By – VonC

Answer Checked By – Terry (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.