首页 > 解决方案 > protobuf 导入 google/protobuf/timestamp.proto

问题描述

我的原型文件是:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

service Foo {
  rpc now(NowRequest) returns (NowResponse) {}
}

message NowRequest {}

message NowResponse {
  google.protobuf.Timestamp now = 1;
}

我生成代码的命令和产生的错误是:

protoc foo.proto --go_out=plugins=grpc,import_path=proto:internal/proto
foo.proto:3:1: Import "google/protobuf/timestamp.proto" was not found or had errors.
foo.proto:12:3: "google.protobuf.Timestamp" is not defined.

我的协议版本是:

protoc --version
libprotoc 3.11.3

我已遵循本指南并查看了此问题。如何导入众所周知的类型?我需要下载其他东西吗?我如何知道我当前安装的确切众所周知的类型是什么?谢谢你。

标签: protocol-buffersgrpcgrpc-go

解决方案


“google/protobuf/timestamp.proto”存储在路径中:/usr/local/include/google/protobuf

请检查您是否有 /usr/local/include/google/protobuf 目录。

如果不是,这意味着 protobuf 安装有错误。请追溯所遵循的安装步骤或尝试重新安装。

请在此处找到更多帮助:https ://github.com/grpc-ecosystem/grpc-gateway/issues/422


推荐阅读