grpc-gateway icon indicating copy to clipboard operation
grpc-gateway copied to clipboard

Allow the generated gateway to import the generated protobuf package

Open alltom opened this issue 7 years ago • 6 comments

I'd like to keep all the proto files in a separate directory than the code that gets generated from them, but I can't find a way to invoke protoc that doesn't assume the generated code is in the same package. Is it possible?

alltom avatar Apr 08 '17 16:04 alltom

I didn't actually run this, but I believe when you run the protoc command you have control of the output directory. To pick the example from the README.md,

protoc -I/usr/local/include -I. \
  -I$GOPATH/src \
  -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
  --grpc-gateway_out=logtostderr=true:. \
  path/to/your_service.proto

The line that says --grpc-gateway_out=logtostderr=true:. has a . at the end which is a reference to the current directory. I think (again, I didn't test this) you can point it anywhere you want.

Good luck!

achew22 avatar Apr 10 '17 04:04 achew22

Hi, same problem here.

The point of separating PB code from GW code is that, I have other repos acting as this repo's client, and thus need to import PB code. However, I don't want to import anything from GW, since it's irrelevant in client.

I can choose where to generate the gateway code, but it seems that the generated code is expecting itself locates in the same package of the PB code. It uses PB types without any package prefix. Any solution here? Thanks!

fengye87 avatar Aug 02 '19 06:08 fengye87

In a brief test with some of my own generated files it seems like it might be possible to generate into a separate folder and import all the types and functions. I think we should be able to support this, but I don't know if we want to add the complexity of figuring out imports to the generator, so ideally it would be something we could turn on with a flag and then use via the go_package option maybe? @fengye87 would you be interested in contributing this new feature?

johanbrandhorst avatar Aug 02 '19 09:08 johanbrandhorst

@johanbrandhorst Glad to know the situation here. I could give it a shot, but no promises :sweat_smile:

fengye87 avatar Aug 05 '19 02:08 fengye87

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 04 '19 03:10 stale[bot]

This is still something users want

johanbrandhorst avatar Apr 16 '20 11:04 johanbrandhorst