go - 协议(protocol) protoc-gen-go "timestamp"未定义

标签 go protocol-buffers grpc

我需要使用 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/

相关文章:

postgresql - 将 gorm.Model 字段集成到 protobuf 定义中

asp.net - 在 .net Core API 版本 3.1 中为 grpc 和 rest API 配置单独的端口

go - 我的 go 二进制文件最终在 src 文件夹中

iterator - 如何创建笛卡尔积

enums - 类型常量声明列表

protocol-buffers - Protobuf 找不到共享库

scala - 单 token 前瞻的性能损失是多少?

eclipse - pom.xml 中的 maven-protoc-plugin 配置不正确

go - 为 golang 中的 proto buf 类型编写自定义 Marshall 和 Unmarshaller

microservices - 如何在 Git proto 存储库中发布对共享 .proto 文件的更改?