我想使用timestamppb
包裹在我的protobufs
因为它有助于轻松转换 Timestamp
至Go
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/