英文:
Golang - google/protobuf/Empty.proto: File not found
问题
以下是翻译好的内容:
syntax = "proto3";
package model;
import "google/protobuf/Empty.proto";
message User {
string id = 1;
string name = 2;
string email = 3;
string alamat = 4;
string password = 5;
}
message UserList {
repeated User list = 1;
}
message userId {
string id = 1;
}
message UserUpdate {
string id = 1;
User user = 2;
}
service Users {
rpc getUserList(google.protobuf.Empty) returns (UserList) {}
rpc getUserById(userId) returns (User) {}
rpc inserUser(User) returns (google.protobuf.Empty) {}
rpc updateUser(UserUpdate) returns (google.protobuf.Empty) {}
rpc deleteUser(userId) returns (google.protobuf.Empty) {}
}
以上是我的proto文件。当尝试编译上述proto文件时,出现了"google/protobuf/Empty.proto: File not found"的错误。有人可以帮我吗?
英文:
syntax = "proto3";
package model;
import "google/protobuf/Empty.proto";
message User {
string id = 1;
string name = 2;
string email = 3;
string alamat = 4;
string password = 5;
}
message UserList {
repeated User list = 1;
}
message userId {
string id = 1;
}
message UserUpdate {
string id = 1;
User user = 2;
}
service Users {
rpc getUserList(google.protobuf.Empty) returns (UserList) {}
rpc getUserById(userId) returns (User) {}
rpc inserUser(User) returns (google.protobuf.Empty) {}
rpc updateUser(UserUpdate) returns (google.protobuf.Empty) {}
rpc deleteUser(userId) returns (google.protobuf.Empty) {}
}
above is my proto file. I get error google/protobuf/Empty.proto: File not found.
when trying to compile the proto file above. can someone help me ?
答案1
得分: 1
首先,正确的导入语句是 import "google/protobuf/empty.proto";
其次,要生成一个 proto 文件,请运行以下代码:
protoc --proto_path={proto_directory_address} --proto_path={proto_directory_name} --go-grpc_out={generated_directory_path} --go_out={generated_directory_path} {proto_directory_address}/{proto_file_name}.proto
英文:
First of all, the correct import is import "google/protobuf/empty.proto";
second, for generating a proto file run this code:
protoc --proto_path={proto_directory_address} --proto_path={proto_directory_name} --go-grpc_out={generated_directory_path} --go_out={generated_directory_path} {proto_directory_address}/{proto_file_name}.proto
答案2
得分: 0
嗨,我知道你遇到了同样的问题很长一段时间了。这个方法对我有效,希望对你也有效:
使用命令行导航到以下目录:
cd .local/include
这个目录通常应该包含一个名为"google"的文件夹,将该文件夹复制并粘贴到以下目录:
/usr/local/include
然后再次尝试使用protoc引擎生成你的项目,如果错误仍然存在,那么尝试以下步骤:
导航到特定的目录,检查是否已经复制过。如果已经复制过,尝试从你所在的文件夹导航到该文件夹(应该是/usr/local/include),如果错误提示你没有权限进入该文件夹,使用以下命令获取权限:
$ sudo chmod o+r -R ./google
然后再次使用上述命令获取相同目录中protobuf文件夹的权限。
完成所有步骤后,再次检查protoc生成器。希望对你有帮助,因为对我有效。
英文:
hi there / i had the same issue for a long time .. this process worked for me i hope it dose for you too :
navigate to this directory using your cmd(command line) :
> cd .local/include
this directory normally should contain some folder named "google" copy this folder and paste it to this directory :
> /usr/local/include
and now try the protoc engine again to generate your project and if the error still exists then try the rest of process :
navigate to that specific directory and check if its been copied or not . if it is then try to navigate to the folder from where you are (which it should be /usr/local/include) if the error says you have no permission to get in the folder
use this command to get the permission
> $ sudo chmod o+r -R ./google
and then try to get permission to get in protobuf folder in the same directory using above command again
when its all done . check the protoc generator again /// hope works for you because it dose for me
答案3
得分: 0
我遇到了同样的问题,因为我没有正确安装 protoc。
要成功安装,请按照以下步骤进行操作:
- 从这里下载最新版本 https://github.com/protocolbuffers/protobuf/releases
- 在你的计算机上解压缩
- 将 bin/protoc 移动到 /usr/local/bin
sudo mv {下载的目录}/bin/protoc /usr/local/bin
- 将 include 文件夹移动到 /usr/local
sudo mv {下载的目录}/include /usr/local
英文:
I had the same problem because I had not installed the protoc correctly
For successful installation do these steps:
- Download latest version from here https://github.com/protocolbuffers/protobuf/releases
- Extract in your computer
- move bin/protoc to /usr/local/bin
sudo mv {downloaded_directory}/bin/protoc /usr/local/bin
- move include folder to /usr/local
sudo mv {downloaded_directory}/include /usr/local
答案4
得分: -2
导入公共库 "google/protobuf/empty.proto"。
英文:
import public "google/protobuf/empty.proto";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论