I am having a hard time figuring out protoc
command and go plugin.
What is the different between:
protoc \
# Directory where you want the compiler to write your Go output.
--go_out=.
# vs ?
--go_opt=paths=source_relative
# vs ?
--go-grpc_out=.
# vs ?
--go-grpc_opt=paths=source_relative
If --go_opt
generate
<name>.pb.go
fileand --go-grpc_opt
generate
<name>_grpc.pb.go
filewhy even have --go_out
?
Can you shed some light on protoc - the doc do not say anything about --go-grpc_opt
?
And and protoc -h
do not even list go as an OUT_DIR?
Note: I install using this doc
why even have --go_out?
So, the thing to understand here is that gRPC is not the same as Protocol Buffers, gRPC uses Protocol Buffers but there are other frameworks that are using them as well. So we need to generate both.
Now, in order to generate the Protocol buffer related code, you need to use --go_out
as you mentioned. but for the gRPC code you need to use --go-grpc_out
.
and --go-grpc_opt generate _grpc.pb.go file
No, --go-grpc_out
does.
Can you shade some light on protoc - the doc do not stay anything about --go-grpc_opt?
Then, before the generation of code you can pass some options and that's what --go_opt
and --go-grpc_opt
are for. The first one passes options for Protobuf generation and the second one for gRPC generation. Options are pretty obscure, and there is not official list of all of them, but you used source_relative
(which tell protoc to use relative paths) for path and there is also the module
option (which help protoc know the go module name to generate in proper folder)
And and protoc -h do not even list go as an OUT_DIR?
And finally, protoc doesn't officially support Go as output, you need to install an external plugin and that's why protoc -h
doesn't show --go_out
. A related discussion can be found here.