Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors running first Go project on local machine

Tags:

github

go

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?

like image 670
Michael Worden Avatar asked Mar 22 '21 04:03

Michael Worden


People also ask

Is Gopath still needed?

Since 1.12 version Go modules is enabled by default and the GOPATH will be deprecated in 1.13 version. For those who are getting started with Go 1.12, the installation and set up goes will be as follows.

What is go mod tidy?

go mod tidy ensures that the go. mod file matches the source code in the module. It adds any missing module requirements necessary to build the current module's packages and dependencies, if there are some not used dependencies go mod tidy will remove those from go.

Where is go mod file?

go mod vendor records the go version from each dependency's go. mod file in vendor/modules.

Where are go dependencies installed?

As we have learned in Go installation tutorial, standard Go packages like located inside GOROOT directory (where Go is installed). Other project-level dependencies are stored inside GOPATH.


1 Answers

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.

like image 139
Shubham Arora Avatar answered Sep 20 '22 06:09

Shubham Arora