我需要使用 Protocol Buffers 序列化從 Google Drive drives:list 方法接收的 JSON 消息,并將它們寫入 BigQuery Storage Write API (GRPC)。這適用于除時(shí)間戳之外的所有字段類型。我終生無法生成包含時(shí)間戳的 go 類。首先,我正在關(guān)注此文檔,盡管我也嘗試了我可以在網(wǎng)上找到的所有內(nèi)容,包括在 stackoverflow 上的此處,但都無濟(jì)于事。在 MacOS 12.6 上,protoc 從此zip安裝到 /usr/local/bin,zip 中包含的內(nèi)容安裝到 /usr/local/include。這是我需要?jiǎng)?chuàng)建一個(gè)類的 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; }}如果我刪除時(shí)間戳類型的字段,該工具會(huì)創(chuàng)建一個(gè)名為 ./driveBuffers/drives.pb.go 的文件。使用時(shí)間戳類型,會(huì)拋出這個(gè)錯(cuò)誤:% protoc --go_out=. -I ./ -I /usr/local/include/ drives.protodrives.proto:11:3: "timestamp" is not defined.
Protoc protoc-gen-go“時(shí)間戳”未定義
函數(shù)式編程
2023-02-14 17:58:38
