Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about flags support what option go_package does #382

Closed
rmrf opened this issue Jun 22, 2017 · 4 comments
Closed

How about flags support what option go_package does #382

rmrf opened this issue Jun 22, 2017 · 4 comments

Comments

@rmrf
Copy link

rmrf commented Jun 22, 2017

I have go through #39, so I'm thinking is that a better way to let protoc support this kind of flag ?

 protoc -I <somewhere> --go_out=go_package=github.com/rmrf/mypackage/pb/foo:. foo.proto

and this have same effort with: add bellow into foo.proto file

option go_package = "github.com/rmrf/mypackage/pb/foo";

or does protoc already have simillary way: which do not need modify .proto file, but generate specific import path package.

@cybrcodr
Copy link
Contributor

I think following invocation should do the same (assuming that foo.proto is in current directory) ...

protoc --go_out=Mfoo.proto=github.com/rmrf/mypackage/pb/foo:. foo.proto

I think specifying inside the proto seems cleaner though and keeps the protoc invocation simpler.

@rmrf
Copy link
Author

rmrf commented Jun 23, 2017

@cybrcodr your invocation is better, Thanks

About why not specify it inside proto, what I'm thinking is: unlike JAVA's java_package com.rmrf.foo, this kind of package naming covention is uniq and does not have relationship with: how to reach the package src code.

Golang's package name have that feature which java don't have.

If I want to generate the golang code for this .proto file, what I'm really need is put this generated golang code into my project, which not only have package name, but also means how to reach it. espestially when I'm working with other team's proto file repo: I can't change theirs .proto file, but I need generate golang src code base on them - and integrate into my project (with my package namespace and url reach way)

That's why this confuse me, I can't figure out better solution yet.

@cybrcodr
Copy link
Contributor

A proto message type should be unique within a binary, unless you're assuming the use of type aliasing or unless it is hidden (internal or vendored), the Go import path of a message type does matter. If you are using another library that uses the same proto message type as your library/binary does and you pass/receive it as argument from that dependent library, then that message type should be the same. That's the reason why I suggested having it in the source proto file for specifying the package path+name, but can certainly be done via invocation as well, in which case, need to make sure that both parties are using the same invocation or same generated code.

Hope that helps.

@cybrcodr
Copy link
Contributor

I'm closing this issue, but feel free to ask more questions.

@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants