我需要使用 Protocol Buffers 序列化从 Google Drive Drives:list 方法接收的 JSON 消息,并将其写入 BigQuery Storage Write API (GRPC)。这适用于除时间戳之外的所有字段类型。我一生都无法生成包含时间戳的 Go 类。首先,我关注this document ,尽管我也尝试了我在网上可以找到的所有方法,包括 stackoverflow 上的这里,但都无济于事。
在 MacOS 12.6 上,protoc 从 this zip 安装到/usr/local/bin 并将 zip 中的 include 内容安装到/usr/local/include。
这是我需要为其创建类的 drivers.proto 文件:
syntax = "proto3";
option go_package = "./driveBuffers";
import "google/protobuf/timestamp.proto";
message Drive {
string id =1;
string name =2;
string colorRgb = 3;
string backgroundImageLink =4;
bool hidden = 5;
string orgUnitId = 6;
timestamp createdTime = 7;
message restrictions {
bool adminManagedRestrictions = 1;
bool domainUsersOnly = 2;
bool copyRequiresWriterPermission = 3;
bool driveMembersOnly = 4;
}
}
如果我删除时间戳类型的字段,该工具将创建一个名为 ./driveBuffers/drives.pb.go 的文件。使用时间戳类型时,会抛出此错误:
% protoc --go_out=. -I ./ -I /usr/local/include/ drives.proto
drives.proto:11:3: "timestamp" is not defined.
谢谢。
最佳答案
您应该将该类型引用为 google.protobuf.Timestamp
。例如:
string orgUnitId = 6;
google.protobuf.Timestamp createdTime = 7;
关于go - 协议(protocol) protoc-gen-go "timestamp"未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73773164/