parseRPCMetadata turns EmptyCall:key1:value1 into {typ: emptyCall, md: {key1:value1}}.
(rpcMetadataStr string, rpcs []string)
| 355 | // |
| 356 | // {typ: emptyCall, md: {key1:value1}}. |
| 357 | func parseRPCMetadata(rpcMetadataStr string, rpcs []string) []*rpcConfig { |
| 358 | rpcMetadataSplit := strings.Split(rpcMetadataStr, ",") |
| 359 | rpcsToMD := make(map[string][]string) |
| 360 | for _, rm := range rpcMetadataSplit { |
| 361 | rmSplit := strings.Split(rm, ":") |
| 362 | if len(rmSplit)%2 != 1 { |
| 363 | log.Fatalf("invalid metadata config %v, want EmptyCall:key1:value1", rm) |
| 364 | } |
| 365 | rpcsToMD[rmSplit[0]] = append(rpcsToMD[rmSplit[0]], rmSplit[1:]...) |
| 366 | } |
| 367 | ret := make([]*rpcConfig, 0, len(rpcs)) |
| 368 | for _, rpcT := range rpcs { |
| 369 | rpcC := &rpcConfig{ |
| 370 | typ: rpcT, |
| 371 | } |
| 372 | if md := rpcsToMD[string(rpcT)]; len(md) > 0 { |
| 373 | rpcC.md = metadata.Pairs(md...) |
| 374 | } |
| 375 | ret = append(ret, rpcC) |
| 376 | } |
| 377 | return ret |
| 378 | } |
| 379 | |
| 380 | func main() { |
| 381 | flag.Parse() |