How to use predifined protobuf type (i.e. "google/protobuf/timestamp.proto") with gRPC
Add /usr/local/include
to include paths to use /usr/local/include/google/api/timestamp.proto
:
protoc -I/usr/local/include -I. --go_out=plugins=grpc:. *.proto
As you can see in timestamp.proto
, Timestamp
exists in package google.protobuf
, so you have to modify to use Timestamp
like this:
message Foo {
google.protobuf.Timestamp modifiedTime = 1;
...
}
It is not fully supported yet, but you can make it work by changing
message Foo {
google.protobuf.Timestamp modifiedTime = 1;
...
}
and by fixing generated file import
import google_protobuf "google/protobuf/timestamp.pb"
to
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
In my case problem was in my Fedora 29 setup.
# Install Protoc compiler. By default it is 3.5.0 version
sudo dnf -y install protoc
This was my bad setup. So i fixed it with following steps. Pay attention to grayed out command lines too.
# Uninstall old 3.5.0 version
sudo dnf remove protobuf
# Make sure you grab the latest version
curl -OL
https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip
# Unzip
unzip protoc-3.6.1-linux-x86_64.zip -d protoc3
# Move protoc to /usr/local/bin/
sudo mv protoc3/bin/* /usr/local/bin/
# Move protoc3/include to /usr/local/include/
sudo mv protoc3/include/* /usr/local/include/
# Optional: change owner
sudo chown $USER /usr/local/bin/protoc
sudo chown -R $USER /usr/local/include/google
After this I am able to use:
import "google/protobuf/timestamp.proto";
message Session {
google.protobuf.Timestamp create_time = 1;
}