You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both of these imports are within the same directory of eachother, but not in the directory of the services/twirp files, and both actually specify the same go_package and package line, as they're only split into multiple files given the size and specific-scope of the messages:
// file: servers.protosyntax="proto3";
packagemodels;
optiongo_package="github.com/lrstanley/spectrograph/internal/models";
[... server-specific messages defined below...]
// file: worker.protosyntax="proto3";
packagemodels;
optiongo_package="github.com/lrstanley/spectrograph/internal/models";
[... worker-specific messages defined below...]
I am able to import both and use them successfully. However, I noticed the generated *.twirp.go files have:
And reference the same go_package as multiple imports throughout the file, which can be rather confusing.
This works successfully (it's supported behavior by protobuf, and from my understanding, not discouraged), however I'm wondering if we can add some logic that ensures if there are multiple imports with the same exact go package name and path, that only one line is imported?
The more serious issue I suspect is: if the current behavior could cause issues for those that use init() functions in their Go packages, where the *.pb.go files are generated, as I suspect these would get executed twice. I.e. if variables or similar are initialized, this could cause weird state issues for users, where two sets of initialized state are used.
The text was updated successfully, but these errors were encountered:
A golang package is initialized only once even if it's imported multiple times by different packages. So the init() function being executed twice shouldn't happen.
If you use /foo/bar/directory/*.proto (bash glob, so if using something like mage, you'll need to expand it first) when you compile the source it should only import it once.
If this is intended behavior, my bad. I tried searching through issues and I couldn't find much.
I have the following proto file (where I have just services defined):
It has two imports:
Both of these imports are within the same directory of eachother, but not in the directory of the services/twirp files, and both actually specify the same
go_package
andpackage
line, as they're only split into multiple files given the size and specific-scope of the messages:I am able to import both and use them successfully. However, I noticed the generated
*.twirp.go
files have:And reference the same
go_package
as multiple imports throughout the file, which can be rather confusing.This works successfully (it's supported behavior by protobuf, and from my understanding, not discouraged), however I'm wondering if we can add some logic that ensures if there are multiple imports with the same exact go package name and path, that only one line is imported?
The more serious issue I suspect is: if the current behavior could cause issues for those that use
init()
functions in their Go packages, where the*.pb.go
files are generated, as I suspect these would get executed twice. I.e. if variables or similar are initialized, this could cause weird state issues for users, where two sets of initialized state are used.The text was updated successfully, but these errors were encountered: