我在编译.proto文件时遇到了问题。希望从.proto文件生成REST端点。以下是代码和错误:语法= "proto3";
package pb;
import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
service UrlShortener {
rpc Hello(HelloRequest) returns (HelloResponse);
rpc Encrypt(EncryptRequest) returns (EncryptResponse);
rpc Decrypt(DecryptRequest) returns (DecryptResponse) {
option (google.api.http) = {
get: "/{hash}"
};
}
}
message HelloRequest {
string Name = 1;
}
message HelloResponse {
string Message = 1;
}
message EncryptRequest {
string OriginalUrl = 1;
}
message EncryptResponse {
UrlMap ResponseMap = 1;
}
message DecryptRequest {
string hash = 1;
}错误: github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis:警告:目录不存在。google/api/annotations.proto:找不到文件。urlshortener.proto:未找到导入"google/api/annotations.proto“或存在错误。
请帮我解决这个问题。
我试过了:去获取-u github.com/grpc-ecosystem/grpc-gateway,但是失败了,它说: path中没有可构建的go源文件。
发布于 2017-09-22 22:27:55
我认为你的定义中有不止一个错误
您在定义的最开始部分缺少语法版本:
syntax = "proto3";有一些未定义的类型
service.proto:32:3: "UrlMap" is not defined.
service.proto:12:40: "DecryptResponse" is not defined.您正在导入未使用的empty.proto
你可以使用下面的googleapies
{GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis然后使用以下命令运行:
protoc -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include -I. service.proto --go_out=plugins=grpc:.我做了前面的更改,它可以编译,所以我有了service.pb.go文件
编辑:
看一下这个grpc网关,也许可以帮助你https://github.com/grpc-ecosystem/grpc-gateway
发布于 2017-09-24 14:42:26
找到了解决方案:问题是google/api/annotations已经从早期的路径grpc-ecosystem/grpc-gateway/third_party/googleapis移动到了https://github.com/grpc-ecosystem/grpc-gateway/tree/master/third_party/googleapis/google/api。
运行以下命令解决了该错误: go get -u github.com/grpc-ecosystem/grpc-gateway/...
https://stackoverflow.com/questions/46358843
复制相似问题