go - 如何在proto文件中导入和使用protobuf timestamppb包?

标签 go protocol-buffers

我想使用timestamppb包裹在我的protobufs因为它有助于轻松转换 TimestampGo time. Time 。但是,我不知道如何将其导入 .proto文件。当我尝试时,出现以下错误 Import "google.golang.org/protobuf/types/known/timestamppb" was not found or had errors.

我查看了文档 timestamppb docs对于timestamppb包,但似乎.proto中没有如何使用它的示例文件。

syntax = "proto3";

import "google.golang.org/protobuf/types/known/timestamppb";
// import "google.golang.org/protobuf/types/known/timestamppb.proto"; I tried this too but no luck

message Example {
  timestamppb.Timestamp example_time = 1;
}

最佳答案

.proto 文件的导入是:

import "google/protobuf/timestamp.proto";

您尝试的是Go代码中与go get结合使用的路径。

关于go - 如何在proto文件中导入和使用protobuf timestamppb包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75397580/

相关文章:

go - 迭代golang无缓冲 channel 时输出困惑

go - Golang Web 服务器的 Heroku 错误 : Web process failed to bind to $PORT within 60 seconds of launch

go - 如何使用 github.com/jhump/protoreflect 解析知道消息描述符的原型(prototype)消息的字节数组

python - 处理返回的 Protocol Buffer 文件

c# - 将 BigDecimal Java 转换为类似 C# 的 Decimal

c - go - 使用 cgo 时, `__GI___pthread_mutex_unlock` 占用了大部分执行时间

go - 分配给 nil 映射中的条目,初始化映射不

go - 按值或引用存储 net.Conn?

c++ - Message::GetDescriptor() 可以返回 null 吗?

c# - 如何为C++、protobuf制作swig接口(interface)文件