2017-09-22 3 views
0

.protoファイルのコンパイルに問題があります。 .protoファイルからRESTエンドポイントを生成します。以下はコードとエラーです: syntax = "proto3";.protoからRESTエンドポイントを自動的に生成します。

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"のインポートが見つかりませんでした。エラーが発生しました。

これを修正するとお手伝いしてください。

私は試しました:go -u github.com/grpc-ecosystem/grpc-gateway しかし、それは言うことに失敗しました。パスにソースファイルがありません。

私はあなたがあなたの定義の先頭に、構文のバージョンが欠落している、あなたの定義の中に複数のエラー

を持っていると思う

答えて

0

syntax = "proto3"; 

いくつかの未定義の型

service.proto:32:3: "UrlMap" is not defined. 
service.proto:12:40: "DecryptResponse" is not defined. 
があります。

あなたはインポートしていますが、使用していませんempty.proto

あなたca

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ファイルを持っている編集:をnはその後使用して実行

{GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis 

からgoogleapiesを使用

このgrpc-gatewayを見て、おそらくお手伝いできます https://github.com/grpc-ecosystem/grpc-gateway

+0

構文= "proto3" を行きます。私のファイルにjusが上記のコードブロックに残っていますが、UrlMap構造体も同様です。ペインティング未編集版のお詫び私は、問題はgoogle/api/annotationsが以前のパスgrpc-ecosystem/grpc-gateway/third_party/googleapisから移動していることを発見しました。次のようにしてエラーを解決しました:go -u github.com/grpc-ecosystem/grpc-gateway/ ... – zaRRoc

+0

@Mayank私は私の答えにその道を言いました! –

関連する問題