What should be a silly protoc golang question

99 views
Skip to first unread message

John

unread,
Jul 22, 2020, 6:02:09 PM7/22/20
to golang-nuts
In essence, I'm switching over to the new go protocol buffer lib and protoc libraries.

In the new version, you are told to specify go_package option in the .proto file.  So I updated all mine to have that:

 go_package = "path/to/my/proto";



I use a script that finds all my proto files and the generates the go files by recursively moving through folders looking for .proto files.

I then enter that directory and do:

/usr/local/bin/protoc -I =./ ./name.proto --go_out=plugins=grpc:./ --proto_path=/home/user/go/src

This works, however it doesn't generate the go files in that directory, it generates it inside the proto's directory with a directory structure like:

./path/to/my/proto/name.pb.go

Where, what I want is: 

name.pb.go

I've tired a bunch of different options, nothing seems to get me what I want.  

Anyone know where I'm going wrong here?

Thanks!




burak serdar

unread,
Jul 22, 2020, 6:14:23 PM7/22/20
to John, golang-nuts
On Wed, Jul 22, 2020 at 4:02 PM John <johns...@gmail.com> wrote:
>
> In essence, I'm switching over to the new go protocol buffer lib and protoc libraries.
>
> In the new version, you are told to specify go_package option in the .proto file. So I updated all mine to have that:
>
> go_package = "path/to/my/proto";
>
>
>
> I use a script that finds all my proto files and the generates the go files by recursively moving through folders looking for .proto files.
>
> I then enter that directory and do:
>
> /usr/local/bin/protoc -I =./ ./name.proto --go_out=plugins=grpc:./ --proto_path=/home/user/go/src

Have you tried the --go_opt=paths=source_relative option?

>
> This works, however it doesn't generate the go files in that directory, it generates it inside the proto's directory with a directory structure like:
>
> ./path/to/my/proto/name.pb.go
>
> Where, what I want is:
>
> name.pb.go
>
> I've tired a bunch of different options, nothing seems to get me what I want.
>
> Anyone know where I'm going wrong here?
>
> Thanks!
>
>
>
>
> --
> 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/ad5c5812-37e3-4f84-bd1d-5fcfcc9cb28eo%40googlegroups.com.

Matthew Walster

unread,
Jul 22, 2020, 6:17:09 PM7/22/20
to John, golang-nuts
John,

On Wed, 22 Jul 2020 at 23:02, John <johns...@gmail.com> wrote:
I then enter that directory and do:

/usr/local/bin/protoc -I =./ ./name.proto --go_out=plugins=grpc:./ --proto_path=/home/user/go/src

This works, however it doesn't generate the go files in that directory, it generates it inside the proto's directory with a directory structure like:

Have you tried using an option like: --go_opt=paths=source_relative

Matthew Walster

John

unread,
Jul 22, 2020, 6:32:06 PM7/22/20
to golang-nuts
Mathew + Burak,

That was it.  

Out of curiosity, where did you find that option.  I didn't see it in protoc's help. google search for "protoc --go_opt" did not yield good results.  It did find: https://grpc.io/docs/languages/go/quickstart/, but I'd like to bookmark the definite list if you know where i can find it.

Cheers and thanks so much!

burak serdar

unread,
Jul 22, 2020, 6:36:26 PM7/22/20
to John, golang-nuts
On Wed, Jul 22, 2020 at 4:32 PM John <johns...@gmail.com> wrote:
>
> Mathew + Burak,
>
> That was it.
>
> Out of curiosity, where did you find that option. I didn't see it in protoc's help. google search for "protoc --go_opt" did not yield good results. It did find: https://grpc.io/docs/languages/go/quickstart/, but I'd like to bookmark the definite list if you know where i can find it.

https://developers.google.com/protocol-buffers/docs/reference/go-generated


>
> Cheers and thanks so much!
>
>
> On Wednesday, July 22, 2020 at 3:17:09 PM UTC-7, Matthew Walster wrote:
>>
>> John,
>>
>> On Wed, 22 Jul 2020 at 23:02, John <johns...@gmail.com> wrote:
>>>
>>> I then enter that directory and do:
>>>
>>> /usr/local/bin/protoc -I =./ ./name.proto --go_out=plugins=grpc:./ --proto_path=/home/user/go/src
>>>
>>> This works, however it doesn't generate the go files in that directory, it generates it inside the proto's directory with a directory structure like:
>>
>>
>> Have you tried using an option like: --go_opt=paths=source_relative
>>
>> Matthew Walster
>
> --
> 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/71f0cd9b-6197-4c1e-94fa-a41df7f8cdeco%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages