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.
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.
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.
Current implementation doesn't support a proto file that has multiple services in it(Basically this should enable running multiple services on same port).
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.
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With