gogo/grpc-example

Code generation a royal pain

bsakweson opened this issue · 1 comments

I am trying to generate code from a .proto file that is basic but good enough to get me started. I have tried for several ours following grpc-example, to no avail. I know I am missing something for sure and here is what I have done so far:

syntax="proto3";

package somepackage

import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "protoc-gen-swagger/options/annotations.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";

option go_package = "client";

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
  info: {
    version: "1.0";
  };
  external_docs: {
    url: "https://localhost:9090/bakalr/api";
    description: "Bakalr Payment Services";
  }
  schemes: HTTPS;
};

// Enable custom Marshal method.
option (gogoproto.marshaler_all) = true;
// Enable custom Unmarshal method.
option (gogoproto.unmarshaler_all) = true;
// Enable custom Size method (Required by Marshal and Unmarshal).
option (gogoproto.sizer_all) = true;
// Enable registration with golang/protobuf for the grpc-gateway.
option (gogoproto.goproto_registration) = true;
// Enable generation of XXX_MessageName methods for grpc-go/status.
option (gogoproto.messagename_all) = true;

service ClientService {
  rpc RegisterClient(Client) returns (Client){
    option (google.api.http) = {
      post: "/api/v1/clients"
      body: "*"
    };
  }
}

enum ClientType {
  unknown = 0;
  mobile = 1;
  web = 2;
  iot = 3;
  pinpad = 4;
  server = 5;
}

message Client {
  string id = 1[(gogoproto.customname) = "ID"];
  ClientType ClientType = 2[(validator.field) = {
    msg_exists : true
    human_error: "Client type must not be unknown"
  }];
  google.protobuf.Timestamp registeredOn = 3[
    (gogoproto.stdtime) = true
  ];
}

The thing is I cannot get this to generate, I get this error Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,: No such file or directory every time I try to generate the code out of that .proto file.

generate: install
	protoc \
		-I client \
		--gogoslick_out=plugins=grpc,\
			Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
			Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
			Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
			$$GOPATH/src/ \
					--grpc-gateway_out=\
			Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
			Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
			Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
			$$GOPATH/src/ \
					--swagger_out=third_party/OpenAPI/ \
					--govalidators_out=gogoimport=true,\
			Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
			Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api,\
			Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types:\
			$$GOPATH/src \
					client/client.proto
install:
	go get \
		github.com/gogo/protobuf/protoc-gen-gogo \
		github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
		github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
		github.com/mwitkow/go-proto-validators/protoc-gen-govalidators \
		github.com/rakyll/statik

I can verify that:

google/protobuf/timestamp.proto
google/api/annotations.proto
google/protobuf/field_mask.proto

Are present in:

github.com/gogo/protobuf/types
github.com/gogo/googleapis/google/api

respectively.

Please let me know what I am missing here.

go version go1.11.2 darwin/amd64
go modules 

I think the problem is your import folders; by saying "-I client" you're telling protoc only to look in that folder to resolve it's imports. You'll notice how this repo has several -I statements in the example makefile.

Furthermore, while I am happy to help, this is not strictly an issue with the repo so I will close it. Please refer to #grpc on gophers.slack.com for more direct help.