Cant find package from $GOROOT and $GOPATH

Answer #1 100 %

All the packages imported are looked in under GOROOT and GOPATH environment variables first. Make sure your package is somewhere under these directories.

Now Suppose GOPATH is set to : /Users/test/Desktop/GoProject

and GOROOT : /usr/local/go (where go is installed) . If a file in your GoProject has a package imported as

import "abc/def/packageName"

then it should be present at any of the below two places:

/Users/test/Desktop/GoProject/src/abc/def/packageName/* /usr/local/go/src/abc/def/packageName/*

If not, you will get error as reported in the question.

The files inside these directories will have the first line as

package packageName

stating that all these files constitutes a package packageName

Answer #2 100 %

As the official document says:

The simplest way is to run go get -u{proto,protoc-gen-go}.

See full introduction here :golang/protobuf installation.

Tags: gogopath

You’ll also like:

© 2023 -