Ошибка выдачи кода VS `` Нет пакета для импорта '', но код компилируется и работает нормально - PullRequest
1 голос
/ 07 августа 2020

В качестве рабочего требования обучение gRPC через онлайн-курс.

У меня есть проект, определенный в папке greet (за пределами GOPATH) с тремя пакетами, называемыми:

  • greet_client
  • greet_server
  • greetpb

enter image description here

In the go.mod file at the root of my project, I've specified the following:

module example.com/myuser/myproject

go 1.14

The code in greet_server/server.go makes a reference to greetpb.

I'm referencing it like the following:

enter image description here

I'm able to run server.go successfully. It returns the expected the result: enter image description here

My question is on the red squiggly lines VSCode throws saying it could not import greetpb: enter image description here

Here's how package greetpb is defined (it's an auto generated file): enter image description here

How can I get rid of this warning message? Is it something I've not setup properly?

Update:

When I try to ctrl+click to view the module greetpb on the file server.go, I note that it's pointing to the url pkg.go.dev.

How can I make the program to do a "local" lookup? введите описание изображения здесь

1 Ответ

0 голосов
/ 07 августа 2020
  1. Зачем использовать example.com? Ваш пакет не определен там.

  2. Сначала инициализируйте go модули, т.е.

go mod init github.com/$USER/$REPO

Go поставщик мода

go mod tidy && go mod vendor

Вот и все.
...