Fwd: protoc-gen-go and go modules

99 views
Skip to first unread message

Amit Saha

unread,
May 12, 2021, 6:47:23 AM5/12/21
to golang-nuts
Hi all, this is only relevant to people using grpc.  I posted the query below to the grpc mailing list, thought of posting it here as welll.

How are you importing the generated definitions and other resources
them into your server and client? As far as I see it now, the protoc
command will not generate a go.mod file in the generated code which
means - you have to do it manually and then import them into your
server and client. That is, you will have three modules:

- One for server
- One for client
- One for the generated code

This seems to be the cleanest approach. During local development, we
will then use the "replace" directive for iteration.

I am keen to hear how it's being done by others in the community.

Thanks,
Amit.

Jim Idle

unread,
May 12, 2021, 9:21:24 PM5/12/21
to Amit Saha, golang-nuts
Create a separate module that contains only the .proto files and use the generate directive. You can then version that module and share it. If your client is some other language, you can generate Its code from the same repo at the same version using your CI. For instance generate a pip wheel as well as the go source. 

By checking in the generated code for all languages, you guarantee that it is in a particular state and that your build is reproducible. It sounds counter intuitive, but Makes sense once you've cogitated on it. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANODV3kqN0wtK5bO3AfVbUhMt1iE9eYvboqbzmSLnY72N6-a6A%40mail.gmail.com.

Amit Saha

unread,
May 13, 2021, 8:11:01 AM5/13/21
to Jim Idle, golang-nuts


On Thu, 13 May 2021, 11:20 am Jim Idle, <ji...@temporal-wave.com> wrote:
Create a separate module that contains only the .proto files and use the generate directive. You can then version that module and share it. If your client is some other language, you can generate Its code from the same repo at the same version using your CI. For instance generate a pip wheel as well as the go source. 

By checking in the generated code for all languages, you guarantee that it is in a particular state and that your build is reproducible. It sounds counter intuitive, but Makes sense once you've cogitated on it. 

Thanks. I think I get it. So the repo containing the .proto files would have a .go file with the generate directives to do the necessary generation. And the go.mod file of course. 
Reply all
Reply to author
Forward
0 new messages