johanbrandhorst/protobuf

Generated proto file has wrong imports

mwei0210 opened this issue · 5 comments

import google_protobuf "google/protobuf"
import google_protobuf1 "google/protobuf"
import google_protobuf2 "google/protobuf"

instead of protoc:

import any "github.com/golang/protobuf/ptypes/any"
import empty "github.com/golang/protobuf/ptypes/empty"
import timestamp "github.com/golang/protobuf/ptypes/timestamp"

Hi! Thanks for raising an issue. Could you show me the .proto file you used and the protoc command used? This doesn't look like it should be happening.

Hi @johanbrandhorst , this would generate an instance of import google_protobuf "google/protobuf"

syntax = "proto3";

package account;

import "google/protobuf/any.proto";

message Account {
    google.protobuf.Any metadata = 1;
}

Yeah so I suspect you're not using the correct type replacing 😬. If you take a look at the example repo you can see that you'll need to use the -M parameter to get the correct imports in the resulting file when using a Google Protobuf Well Known Type (such as any.proto or timestamp.proto):

https://github.com/johanbrandhorst/grpcweb-example/blob/master/Makefile#L4

protoc -I. -Ivendor/ proto/library/book_service.proto \
    	--gopherjs_out=plugins=grpc,Mgoogle/protobuf/timestamp.proto=github.com/johanbrandhorst/protobuf/ptypes/timestamp:$$GOPATH/src \
    	--go_out=plugins=grpc:$$GOPATH/src

If you try using --gopherjs_out=plugins=grpc,Mgoogle/protobuf/any.proto=github.com/johanbrandhorst/protobuf/ptypes/any, it should work :). Let me know how it goes!

ah it works now thanks! Is there anyway to automate it?

Unfortunately this M-parameter always has to be supplied to protoc since the source file you're using declares option go_package = github.com/golang/protobuf/ptypes/any. Glad it fixed your use case though!