Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve import in .proto file

I have created following .proto file in the path: microservice/internal/proto-files/domain/repository.proto

syntax = "proto3";

package domain;

option go_package = "microservice/internal/gRPC/domain";

message Repository {
  int64 id  = 1;
  string name = 2;
  int64 userId = 3;
  bool isPrivate = 4;
}

and also following .proto file in another path: microservice/internal/proto-files/service

syntax = "proto3";

package service;

option go_package = "microservice/internal/gRPC/service";

import "microservice/internal/proto-files/domain/repository.proto";

//RepositoryService Definition
service RepositoryService {
  rpc add (domain.Repository) returns (AddRepositoryResponse);
}

message AddRepositoryResponse {
  domain.Repository addedRepository = 1;
  Error error = 2;
}
message Error {
  string code = 1;
  string message = 2;
}

but my IDE(goland) cannot resolve import in repository-service.proto and also when I use protoc command to generate .pb.go file, I will face following error:

microservice/internal/proto-files/domain/repository.proto: File not found.
like image 231
Siavoosh Avatar asked Aug 21 '20 16:08

Siavoosh


People also ask

How do I import Proto from another project?

In the service project, you need to add a proto file, then add the Protobuf element to the ItemGroup. Then you need to build the project. After that, in the client's project, you need to add the Protobuf element to the ItemGroup and build the project.

Can proto3 import proto2?

It's possible to import proto3 message types and use them in your proto2 messages, and vice versa. However, proto2 enums cannot be used in proto3 syntax.

Can a proto file have multiple services?

Current implementation doesn't support a proto file that has multiple services in it(Basically this should enable running multiple services on same port).

What is proto file in gRPC?

proto file Protocol buffers (protobuf) are used as the Interface Definition Language (IDL) by default. The . proto file contains: The definition of the gRPC service. The messages sent between clients and servers.


Video Answer


1 Answers

First of all, your import path is better to be like this :

import "domain/repository.proto";

You must add the path of your proto files to your Goland. for that you must go to setting > Languages & Frameworks > Protocol Buffers then uncheck Configure automatically.

After that add this path on import paths.

microservice/internal/proto-files

like this : enter image description here

like image 182
ttrasn Avatar answered Oct 01 '22 11:10

ttrasn