As the protocol-buffers documentation describes:
Each map field generates a field in the struct of type
map[TKey]TValue
whereTKey
is the field's key type andTValue
is the field's value type...
I would like to set TValue
to be a slice of string. So that in Go it generates:
map[string][]string
Considering also this note on repeated fields:
Likewise, for the field definition
repeated bytes foo = 1;
the compiler will generate a Go struct with a[][]byte
field namedFoo
I'm trying to do the following:
message CallBackUrl {
string base_url = 1;
map<string, repeated string> params = 2;
}
But this just spits an error:
pb/authenticator.proto:57:26: Expected ">"
I could do this:
message StringSlice {
repeated string slice = 1;
}
message CallBackUrl {
map<string, StringSlice> params = 1;
}
Outputs:
type StringSlice struct {
Slice []string
}
type CallBackUrl struct {
Params map[string]*StringSlice
}
However, in the implementation Params
will need to be used as an url.Values
to build a query string. This last solution would required an additional iteration, and copying the data into a new map[string][]string
, which I would like to avoid.
(How) can I make protocol-buffers generate a (Go) map of string slices? I'm using the gRPC plugin.