moul / protoc-gen-gotemplate

:open_file_folder: generic protocol generator based on golang's text/template (grpc/protobuf)
https://manfred.life/protoc-gen-gotemplate
MIT License
438 stars 70 forks source link

handle import of proto file #58

Closed jhayotte closed 7 years ago

jhayotte commented 7 years ago

This PR is a proposal to enhance protoc-gen-gotemplate on a specific point: Handle the statement import of Protobuffer in our generator. Thus we can share proto's definition and structure them better.

To make it work, I had to tweak goType in helpers.go. If you have a better idea do not hesitate to suggest it :)

I wrote an example of import to show how it works.

jhayotte commented 7 years ago

I added a helper that wraps goType for this use case. PS: I tried doing something a bit more elegant with {{$f | goType {{$f | goPackage}}}} but the generator did not like { as parameter. If you think it's doable and that's really more elegant, tell me.