grpc-ecosystem/grpc-gateway

Support query param unmarshalling to a map with a slice value-type

オープン

#1,108 opened on 2020/01/09

 (13 件のコメント) (0 件のリアクション) (0 人の担当者)Go (2,250 件のフォーク)batch import
enhancementhelp wanted

Repository metrics

Stars
 (16,971 個のスター)
PR merge metrics
 (平均マージ 8d 23h) (30d で 147 merged PRs)

説明

grpc-gateway has an odd restriction on query parameters with map types. Specifically, it refuses to unmarshal a map type whether the value type is a string slice, such as map[string][]string.

grpc-gateway makes the assumption that the underlying Go type is authoritative for it's representation in query parameters.

I would expect ?q[foobar]=hello&q[foobar]=world to successfully unmarshal to both a map[string][]string if using GoGo protobuf's custom type mappings as well as the following type raw protobuf type:

message MapStringSlice {
  string key = 1;
  string value = 2;
}

message RPC {
   repeated MapStringSlice q = 1;
}

The wire representation of this type is identical to proto's map<string, string> and is recommended for backwards compatibility by the documentation for implementations that may not support map:

I'm happy to write a patch for this functionality if it's welcomed by the maintainers.

コントリビューターガイド