Answer the question
In order to leave comments, you need to log in
What should be written in proto files in option go_package?
Hello. I'm trying to understand protobuf code generation. Currently, .proto files must have option go_package . But I don’t understand what to indicate here ... Or I have a problem understanding the folder structure.
If I specify "example.com/project/protos/fizz" , then protoc will create 4 folders for me (example.com, project.protos.fizz). Not sure if this is correct. But even if so, then it is not possible to connect the generated file. If you do go mod init ... , then again it is not clear what to specify in go_package. The go mod tidy command cannot find this package.
Do I need to upload the code to github and already specify the path from github? And if I just want to experiment on a computer, without a github. The question is probably simple, but I ask you to help me figure it out so that it settles in my head. Dock from Google did not give answers, well, or I'm not reading there.
Answer the question
In order to leave comments, you need to log in
You need to specify the full path to the package where the generated files will be located.
In your case (if you keep the generated and proto files in /protos/fizz)
option go_package = "example.com/project/protos/fizz";
then run the generation with the option
--go_opt=paths=source_relative
If the paths=source_relative flag is specified, the output file is placed in the same relative directory as the input file. For example, an input file protos/buzz.proto results in an output file at protos/buzz.pb.go.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question