I have an existing project in Go where I'm using Protocol buffers / gRPC. Until recent the go_package
option was optional and the resulting Go package name would be the same as the proto package name.
This file lives in the project root. The generated code file (authenticator.pb.go
) is living in the same location. Proto file:
syntax = "proto3";
package authenticator;
service Authenticator {...}
Generation command specifies I want to output in the same directory:
protoc --go_out=plugins=grpc:. authenticator.proto
Today I've pulled new version of the protocol buffers compiler and github.com/golang/protobuf/protoc-gen-go
. Upon the first run a got a warning:
WARNING: Missing 'go_package' option in "authenticator.proto",
please specify it with the full Go package path as
a future release of protoc-gen-go will require this be specified.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.
The suggested link is more or less useless. But the tutorial is a bit more explicit:
The go_package option defines the import path of the package which will contain all the generated code for this file. The Go package name will be the last path component of the import path. For example, our example will use a package name of "tutorialpb".
option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb";
After adding this option to the proto file and rerunning the command, the output ends up in this path, relative to the project root. Something like:
$GOPATH/src/github.com/<org>/authenticator/github.com/<org>/authenticator/authenticator.pb.go
I've tried the following alternatives as go_package
names:
.
authenticator
Generation happened in the correct location, but I got the warning back:
WARNING: Deprecated use of 'go_package' option without a full import path...
So what is the correct way without breaking the project layout?
go_opt=module
but it doesn't work withsource_relative
. – Furiya