英文:
How to import and use protobuf timestamppb package in a proto file?
问题
我想在我的protobufs
中使用timestamppb
包,因为它可以方便地将Timestamp
转换为Go
的time.Time
。然而,我无法弄清楚如何将其导入到.proto
文件中。当我尝试时,我会得到以下错误信息:Import "google.golang.org/protobuf/types/known/timestamppb" was not found or had errors.
我查看了timestamppb
包的文档timestamppb文档,但似乎没有关于如何在.proto
文件中使用它的示例。
syntax = "proto3";
import "google.golang.org/protobuf/types/known/timestamppb";
message Example {
google.protobuf.Timestamp example_time = 1;
}
英文:
I want to use timestamppb
package in my protobufs
because it helps to easily convert Timestamp
to Go
time. Time
. However, I can't figure out how to import it into the .proto
file. When I try I get the following error Import "google.golang.org/protobuf/types/known/timestamppb" was not found or had errors.
I looked at the documentation timestamppb docs for the timestamppb
package but it seems there are no examples of how to use it in .proto
files.
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;
}
答案1
得分: 3
.proto
文件的导入方式是:
import "google/protobuf/timestamp.proto";
你尝试的那个路径是在Go代码中与go get
结合使用时所需的路径。
英文:
The import for .proto
files is:
import "google/protobuf/timestamp.proto";
The one that you tried is the path that is needed in Go Code in combination with go get
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论