我对GRPC比较陌生,并且在我的proto文件中发现了一个错误,我似乎无法理解。我想使用"google.protobuf.Timestamp“在消息中发送时间。我似乎不能导入它。我做错了什么?
syntax = "proto3";
import "google/protobuf/timestamp.proto";
service ProfileService {
rpc ConstructProfileStructFromUser (ConstructProfileStructFromUserRequest) returns (ConstructProfileStructFromUserResponse);
}
message ConstructProfileStructFromUserRequest {
string transactionID = 1;
string User = 2;
}
message ConstructProfileStructFromUserResponse {
string UID = 1;
string ContactEmail = 2;
google.protobuf.Timestamp DateOfBirth = 3;
}
在我的IDE和编译器中(使用下面的命令),我都会得到错误
google/protobuf/timestamp.proto: File not found.
profile.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
profile.proto:21:5: "google.protobuf.Timestamp" is not defined.
要运行的命令:
protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile
Protoc --版本
libprotoc 3.0.0
发布于 2019-11-28 20:26:36
我遇到了这个问题--我使用apt包管理器(ubuntu)安装了protoc编译器,它把protoc编译器放在了像/usr/local/bin
这样的地方,在默认情况下,protoc期望并要求导入存在于与这个.e.g相关的包含路径中。/usr/local/bin/protoc
旁边的/usr/local/bin/include/*
。
为了修复这个问题,我使用apt删除了安装的版本,并从github页面下载了最新的版本- github.com/protocolbuffers/protobuf/releases,查找适用于您的os/arch的protoc下载(例如protoc-3.13.0-linux-x86_64.zip
),该下载包含所需的内容(在inlcude
文件夹中)。只需将include文件夹放在路径中二进制文件的旁边。
发布于 2019-05-08 12:57:25
我的问题很简单...
我没有在本地下载timestamp.proto,因此它找不到它。
我克隆了:
https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf
然后,当我运行我的编译器时,我必须给它提供定位timestamp.proto文件的位置。
对我来说这是..。
protoc -I profile/ -I MY_CLONED_REPO_LOCATION/protobuf/src profile/profile.proto --go_out=plugins=grpc:profile
一旦它知道它在哪里有通向源代码的路径,它就可以毫不费力地找到它。
发布于 2020-04-01 17:57:14
我从ubuntu repo安装的protoc 3.0.0也遇到了同样的问题。我找到了另一个解决方案,不用像@SwiftD建议的那样重新安装protobuf,使用--proto_path proto选项。在您的.proto导入中应如下所示(即没有路径):
syntax = "proto3";
import "timestamp.proto"
然后,在protoc调用中,使用--proto_path选项将绝对路径传递到包含timestamp.proto的包目录(我使用github.com/golang/protobuf/ptype/timestamp)。
protoc kcproto.proto --go_out=./ --proto_path=/home/my_home_dir_name/go/src/github.com/golang/protobuf/ptypes/timestamp --proto_path=./
将/home/my_home_dir_name/替换为go包目录
https://stackoverflow.com/questions/56031098
复制相似问题