Protobuf: No documentation about go_package option

Created on 1 Dec 2020  路  5Comments  路  Source: golang/protobuf

Hi, I tried to understand what protobuf option option go_package = ".;types" do.
But seems like protobuf have no documentation about it.
Maybe we need to add?

We have only an old issue explaining this https://github.com/golang/protobuf/issues/139

Most helpful comment

I just updated the documentation at https://developers.google.com/protocol-buffers/docs/reference/go-generated#package with a bit more detail on go_package.

The go_package option should contain the full import path of the Go package which contains the generated code for the .proto file. The Go package name will be derived from the last path component of the import path. The package name may be overridden by appending ;<package_name> to the go_package option, but this should be seldom, if ever used, since Go package names should almost always be directly related to the package import path.

option go_package = ".;types" states that the Go import path is "." and the Go package name is types. Since an import path of "." is clearly incorrect, this is not a reasonable value for the go_package option.

If a tutorial is suggesting that value for the go_package option, the tutorial should be fixed.

All 5 comments

It's documented at https://developers.google.com/protocol-buffers/docs/gotutorial#defining-your-protocol-format and https://developers.google.com/protocol-buffers/docs/reference/go-generated#invocation.

The godoc package page for protoc-gen-go has little documentation for how it operates since it points to https://developers.google.com/protocol-buffers/ which has more comprehensive documentation about the invocation of protoc and the meaning of .proto options.

I should note that go_package = ".;types" is a non-sensible value since it should be set to the Go import path for the Go package that is generated for that .proto file. An import path of . is pretty meaningless.

@dsnet in this docs no mention about the meaning of first and second part of option value "first;second".
But if you will just follow any tutorial you will see the hint while generating: please add option go_package = ".;types"

Screenshot 2020-12-02 at 02 51 21

I just updated the documentation at https://developers.google.com/protocol-buffers/docs/reference/go-generated#package with a bit more detail on go_package.

The go_package option should contain the full import path of the Go package which contains the generated code for the .proto file. The Go package name will be derived from the last path component of the import path. The package name may be overridden by appending ;<package_name> to the go_package option, but this should be seldom, if ever used, since Go package names should almost always be directly related to the package import path.

option go_package = ".;types" states that the Go import path is "." and the Go package name is types. Since an import path of "." is clearly incorrect, this is not a reasonable value for the go_package option.

If a tutorial is suggesting that value for the go_package option, the tutorial should be fixed.

@neild Big thanks for documenting, this is just what I needed.

Was this page helpful?
0 / 5 - 0 ratings