2016-10-26 27 views
4

grpc golang을 사용하여 클라이언트와 서버 응용 프로그램간에 통신합니다. 다음은 protoc 버퍼의 코드입니다.gRPC protoc 버퍼에서 map [string] 인터페이스 {} 변수를 생성합니다.

syntax = "proto3"; 
package Trail; 

service TrailFunc { 
    rpc HelloWorld (Request) returns (Reply) {} 
} 

// The request message containing the user's name. 
message Request { 
    map<string,string> inputVar = 1; 
} 
// The response message containing the greetings 
message Reply { 
    string outputVar = 1; 
} 

map [string] 문자열 대신 message 데이터 구조 내에 map [string] interface {} 유형의 필드 inputVar를 만들어야합니다. 어떻게 구현할 수 있습니까? 미리 감사드립니다.

+0

을. 하지만'map '가 작동 할 수도 있습니다. – Vatine

답변

2

proto3는 Any

import "google/protobuf/any.proto"; 

message ErrorStatus { 
    string message = 1; 
    repeated google.protobuf.Any details = 2; 
} 

을 입력 가지고 있지만 그 구현 보면, 그것은 당신이 가능하게 반사와 중간 형식을 사용하여 이러한 메시지를 직접 정의 할 필요가

message Any { 
    string type_url = 1; 
    bytes value = 2; 
} 

로 단순히 .

는, 프로토콜 버퍼에서 "구조체"형식은 [문자열] 인터페이스는 {} golang의지도에 아마 가까운 https://github.com/golang/protobuf/issues/60

0

가 다루는 자세한 조금 얻을 수 있지만 example application

참조

그러나 비슷한 인터페이스 {}는 실제로 저장된 유형이 무엇인지 판단하기 위해 반사 스타일 오버 헤드를 취합니다.

예를 들어 여기에 의견을 참조하십시오 : "당신이 원하지 않는"같은 소리 오프 손 https://github.com/golang/protobuf/issues/370