我需要使用协议缓冲区来序列化从Google Drive Drives:List方法接收的JSON消息,并将它们写入BigQuery存储写入API(GRPC).这适用于除TIMESTAMP之外的所有字段类型.我无论如何都不能生成包含时间戳的围棋类.首先,我关注了this document个,虽然我也try 了所有我能在网上找到的东西,包括这里的Stackoverflow,但都没有用.

在MacOS 12.6上,Protoc从this zip安装到/usr/local/bin,压缩包中的Include内容安装到/usr/local/Include.

这是我需要为其创建类的drives.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;
  }
}

如果我删除类型为TIMESTAMP的字段,该工具将创建一个名为./driveBuffers/drives.pb.go的文件.对于TIMESTAMP类型,抛出以下错误:

% 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相关问答推荐

GORM没有从 struct 创建完整的表,如何修复?

将类型定义为泛型类型实例化

JetBrains Goland,禁用突出显示测试文件

如果values.yaml文件中不存在某个属性,如何返回默认的FALSE?

如何配置vscode以在Go中显示不必要的(过度指定的)泛型?

Kafka架构注册表-Broker:Broker无法验证记录

Golang:访问any类型泛型上的字段

Go:如何在不加载正文的情况下创建 http 代理通行证

如何在 Go 服务中导入 monorepo 中的包?

如何判断范围内的字段?

使用 Golang 在字符串中循环重复数据

如何使用 Go 获取 X11 中的窗口列表

在 docker kill --signal=SIGX 上以这种方式关闭容器内运行的 go 应用程序是否安全?

如何使用 math/big 对 bigInt 进行取模?

Golang - 无法从 pipped Windows 命令中获取结果

GORM GIN 更新查询导致 500 内部服务器错误

如何在 Unmarshal 中使用泛型(转到 1.18)

gopls 为 github.com/Shopify/sarama 返回错误gopls: no packages returned: packages.Load error

将函数的值作为输入参数返回给另一个

Go http标准库中的内存泄漏?