Michael Worden
Michael Worden

Reputation: 173

Errors running the first Go project on the local machine

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?

Upvotes: 15

Views: 40042

Answers (3)

Dimi Ansari
Dimi Ansari

Reputation: 404

If you're on macOS, run the following command first and then retry:

xcode-select --install

Reference: Why am I getting an “invalid active developer path” when attempting to use Git after upgrading to macOS Monterey?

Upvotes: 0

Shubham Arora
Shubham Arora

Reputation: 947

This is what worked for me.

Step 1. Delete any previous Go version if you are doubtful about having it configured properly.

Step 2. Install new Go version. Download the binary release (Go) from here Go Binary Download

Note: In order to delete and install the new Go version you can use these steps - Go Deletion and Installation, they worked for me. Also the version I am currently using is 1.16.3.

Step 3. After completing step 1 and step 2, run the following command in a terminal:

go env -w GO111MODULE=auto

This should do it.

Upvotes: 25

VonC
VonC

Reputation: 1325137

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.

Upvotes: 8

Related Questions