1

Hi I installed golang grpc in my vscode project with some go get commands,

go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go

go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc

from https://stackoverflow.com/a/62872353/4159198

my project builds/runs inside vscode and on the command line but autocomplete gives me an error,

could not import google.golang.org/grpc (cannot find package "google.golang.org/grpc" in any of 
    /usr/local/go/src/google.golang.org/grpc (from $GOROOT)
    /home/john/go/src/google.golang.org/grpc (from $GOPATH))

Find from my home directory:

find * -iname google.golang.org
go/src/google.golang.org
go/pkg/mod/google.golang.org
go/pkg/mod/cache/download/google.golang.org
go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/google.golang.org

My .profile bottom,

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:~/go

export GOPATH=/home/john/go
export PATH=$PATH:$GOPATH/bin

I tried copying the source from pkg to src directory.

shwick
  • 4,277
  • 6
  • 21
  • 28
  • 1
    The 2 `go get` commands only get|install the packages from `google.golang.org/grpc/cmd` called `protoc-gen-go` and `protoc-gen-grpc-go`. In your project (directory) (containing `go.mod` that should include references to `google.golang.org/grpc`) you will want to `go mod tidy` to pull the entire module. Do you have the [Go extension](https://code.visualstudio.com/docs/languages/go) installed in VSCode? – DazWilkin Dec 26 '21 at 20:39
  • 1
    What's in your go.mod file? – Hana Dec 29 '21 at 02:05

1 Answers1

3

Try to launch go mod init on every program you want to compile. If there was packages to imported and it missing, there will be a lightbulb icon that you can click on to automatically go get the packages you want It will look like this

On your go.mod will there written

google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.25.0 // indirect