gRPCを実装する際に以下のようなuser.protoファイルを作成しました。そして、protocコマンドを実行したところ、以下のようなエラーが出ました。解決法を紹介します。
user.proto
syntax = "proto3";
package pb;
import "google/protobuf/timestamp.proto";
option go_package = "./pb";
message User {
string name = 1;
google.protobuf.Timestamp updated_at = 2;
google.protobuf.Timestamp created_at = 3;
}
エラー文
timestamp.proto: File not found.
user.proto:5:1: Import "timestamp.proto" was not found or had errors.
user.proto:11:5: "google.protobuf.Timestamp" is not defined.
user.proto:12:5: "google.protobuf.Timestamp" is not defined.
解決法
こちらに解決法が記載されていました。
https://github.com/protocolbuffers/protobuf/issues/5131
具体的には以下のコマンド実行します。
apk add protobuf-dev
私の場合はDockerを用いて開発を行っていたのでDockerfileに以下の処理を追加しました。
Dockerfile
・
・
RUN apk add protobuf-dev
・
・