protobuf avoid namespace conflict

3,824 views
Skip to first unread message

Vasiliy Tolstov

unread,
Sep 29, 2020, 3:52:00 AM9/29/20
to golan...@googlegroups.com
Hi! I have two packages server and client. All belongs to different
repos. In this packages i have internal/errors dir with errors.proto
file
Both of them contains go_package option and package unique

option go_package = "xxx.org/server/internal/errors";
package server.errors;

option go_package = "xxx.org/client/internal/errors";
package client.errors;

why program that used client and server in the same time have such message

2020/09/29 10:50:18 WARNING: proto: file "errors.proto" is already registered
previously from: ""xxx.org/server/internal/errors"
currently from: ""xxx.org/client/internal/errors"
A future release will panic on registration conflicts. See:
https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict

--
Vasiliy Tolstov,
e-mail: v.to...@selfip.ru

Vasiliy Tolstov

unread,
Sep 30, 2020, 9:27:30 AM9/30/20
to golan...@googlegroups.com
So nobody knows how to deal with this? And if some projects have proto
files with the same name - protobuf always complain about it?

вт, 29 сент. 2020 г. в 10:50, Vasiliy Tolstov <v.to...@selfip.ru>:

Joop Kiefte

unread,
Sep 30, 2020, 9:42:09 AM9/30/20
to v.to...@selfip.ru, golan...@googlegroups.com
This seems to be because the protocol buffer packages rely on shared state, kinda similar to the registration of database drivers in database/sql I would say (correct me if I'm wrong). I don't know how you import them, but you probably need a way to strictly separate the two in your program (example code would help to give more specific advice...).
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CACaajQvaGd8j2MD75EkRvH6zxD89gyKLunxXL6Q5%3DN9VkKWWhQ%40mail.gmail.com.


Vasiliy Tolstov

unread,
Sep 30, 2020, 11:14:04 AM9/30/20
to Joop Kiefte, Василий Толстов, golan...@googlegroups.com

Denis Cheremisov

unread,
Sep 30, 2020, 1:47:14 PM9/30/20
to golang-nuts
It is because you import protoc-gen-go generated entities with exactly the same package name and their own name. This is not allowed with protobuf, you can only have a single <pkg name>.<entity name>. You can either use different names for error packages or use a 3rd repository with generated code.

среда, 30 сентября 2020 г. в 18:14:04 UTC+3, va...@selfip.ru:

Joop Kiefte

unread,
Sep 30, 2020, 2:56:22 PM9/30/20
to denis.ch...@gmail.com, golan...@googlegroups.com
I suppose the best way is to use namespaced naming for the imported packages

pgu9m
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/5df715d7-ba19-46e5-ad1d-1c5dd5c896ddn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages