google/protobuf/empty.proto: File not found.
来源:1-7 docker和docker-compose的安装

坨坨的仓鼠
2021-11-29
错误提示:
google/protobuf/empty.proto: File not found.
user.proto:2:1: Import "google/protobuf/empty.proto" was not found or had errors.
user.proto:10:44: "google.protobuf.Empty" is not defined.
执行protoc --go_out=. --go-grpc_out=. user.proto
报错。
但是在 user.proto
中可以正常跳转到 empty.proto
。
在python中执行python -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I. user.proto
编译正常。
请问是什么原因
附上user.proto
:
syntax = "proto3";
import "google/protobuf/empty.proto";
option go_package = ".;proto";
service User {
rpc GetUserList(PageInfo) returns (UserListResponse); //用户列表
rpc GetUserByMobile(MobileRequest) returns (UserInfoResponse); //用户信息
rpc GetUserById(IdRequest) returns (UserInfoResponse); //用户信息
rpc CreateUser(CreateUserInfo) returns (UserInfoResponse); //创建用户
rpc UpdateUser(UpdateUserInfo) returns (google.protobuf.Empty); //更新用户
}
message PageInfo {
uint32 pn = 1;
uint32 pSize = 2;
}
message MobileRequest{
string mobile = 1;
}
message IdRequest{
int32 id = 1;
}
message CreateUserInfo{
string nickname = 1;
string password = 2;
string mobile = 3;
}
message UpdateUserInfo{
int32 id =1;
string nickname = 2;
string gender = 3;
uint64 birthday = 4;
}
message UserInfoResponse{
int32 id = 1;
string password = 2;
string mobile = 3;
string nickname = 4;
uint64 birthday = 5;
string gender = 6;
int32 role = 7;
string address = 8;
}
message UserListResponse {
int32 total = 1;
repeated UserInfoResponse data = 2;
}
写回答
1回答
-
bobby
2021-11-29
有些人安装protobuf插件的时候容易出这个问题,可以将google的
这里的路径中的proto文件拷贝到自己的目录下,然后不要import,一般情况下为了防止这种问题,可以将所有依赖的第三方proto文件都拷贝到自己的目录下,然后protoc命令运行的时候指定一下输入的proto文件的路径就可以了
112021-11-29
相似问题