How to import and use protobuf timestamppb package in a proto file?

huangapple go评论88阅读模式
英文:

How to import and use protobuf timestamppb package in a proto file?

问题

我想在我的protobufs中使用timestamppb包,因为它可以方便地将Timestamp转换为Gotime.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.

huangapple
  • 本文由 发表于 2023年2月9日 18:54:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75397580.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定