0
votes

I am having problem with compiling the .proto file. Looking to generate REST endpoints from the .proto files. Below is the code and error : syntax = "proto3";

package pb;

import "google/protobuf/empty.proto";
import "google/api/annotations.proto";

service UrlShortener {
  rpc Hello(HelloRequest) returns (HelloResponse);

  rpc Encrypt(EncryptRequest) returns (EncryptResponse);

  rpc Decrypt(DecryptRequest) returns (DecryptResponse) {
    option (google.api.http) = {
                get: "/{hash}"
            };
  }
}

message HelloRequest {
  string Name = 1;
}

message HelloResponse {
  string Message = 1;
}

message EncryptRequest {
  string OriginalUrl = 1;
}

message EncryptResponse {
  UrlMap ResponseMap = 1;
}

message DecryptRequest {
  string hash = 1;
}

Error : github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis: warning: directory does not exist. google/api/annotations.proto: File not found. urlshortener.proto: Import "google/api/annotations.proto" was not found or had errors.

Please help with fixing this.

I tried : go get -u github.com/grpc-ecosystem/grpc-gateway But it failed saying : no buildable go source files in path.

2

2 Answers

0
votes

I think you have more than one errors in your definition

You are missing the syntax version at the very beginning of your definition:

syntax = "proto3";

There are some undefined types

service.proto:32:3: "UrlMap" is not defined.
service.proto:12:40: "DecryptResponse" is not defined.

You are importing and unused empty.proto

You can use the googleapies from

{GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis

Then run using:

protoc -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include -I. service.proto --go_out=plugins=grpc:.

I made the previous changes and it compiles, so I have the service.pb.go file

Edited:

Take a look of this grpc-gateway, maybe can help you https://github.com/grpc-ecosystem/grpc-gateway

0
votes

Found out the solution : The problem is that google/api/annotations has moved from the earlier path grpc-ecosystem/grpc-gateway/third_party/googleapis to https://github.com/grpc-ecosystem/grpc-gateway/tree/master/third_party/googleapis/google/api.

Running the following resolved the error : go get -u github.com/grpc-ecosystem/grpc-gateway/...