2017-09-22 11 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 get -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 N 그런 다음 사용하여 실행

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

에서 googleapies를 사용

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-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 나는 내 대답에서 그 경로를 언급했습니다! –