|
1 | 1 | func (c *fooGRPCClient) GetAnotherThing(ctx context.Context, req *mypackagepb.InputType, opts ...gax.CallOption) (*mypackagepb.OutputType, error) { |
2 | | - var routingHeaders []string |
3 | | - seen := make(map[string]bool) |
| 2 | + routingHeaders := "" |
| 3 | + routingHeadersMap := make(map[string]string) |
4 | 4 | if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetOther()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetOther())[1])) > 0 { |
5 | | - if !seen["other"] { |
6 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "other", url.QueryEscape(reg.FindStringSubmatch(req.GetOther())[1]))) |
7 | | - seen["other"] = true |
8 | | - } |
| 5 | + routingHeadersMap["other"] = url.QueryEscape(reg.FindStringSubmatch(req.GetOther())[1]) |
9 | 6 | } |
10 | 7 | if reg := regexp.MustCompile("(?P<name>projects/[^/]+)/foos"); reg.MatchString(req.GetOther()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetOther())[1])) > 0 { |
11 | | - if !seen["name"] { |
12 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "name", url.QueryEscape(reg.FindStringSubmatch(req.GetOther())[1]))) |
13 | | - seen["name"] = true |
14 | | - } |
| 8 | + routingHeadersMap["name"] = url.QueryEscape(reg.FindStringSubmatch(req.GetOther())[1]) |
15 | 9 | } |
16 | 10 | if reg := regexp.MustCompile("(?P<foo_name>projects/[^/]+)/bars/[^/]+(?:/.*)?"); reg.MatchString(req.GetAnother()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1])) > 0 { |
17 | | - if !seen["foo_name"] { |
18 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "foo_name", url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1]))) |
19 | | - seen["foo_name"] = true |
20 | | - } |
| 11 | + routingHeadersMap["foo_name"] = url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1]) |
21 | 12 | } |
22 | 13 | if reg := regexp.MustCompile("(?P<foo_name>projects/[^/]+/foos/[^/]+)/bars/[^/]+(?:/.*)?"); reg.MatchString(req.GetAnother()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1])) > 0 { |
23 | | - if !seen["foo_name"] { |
24 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "foo_name", url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1]))) |
25 | | - seen["foo_name"] = true |
26 | | - } |
| 14 | + routingHeadersMap["foo_name"] = url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1]) |
27 | 15 | } |
28 | 16 | if reg := regexp.MustCompile("(?P<foo_name>.*)"); reg.MatchString(req.GetAnother()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1])) > 0 { |
29 | | - if !seen["foo_name"] { |
30 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "foo_name", url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1]))) |
31 | | - seen["foo_name"] = true |
32 | | - } |
| 17 | + routingHeadersMap["foo_name"] = url.QueryEscape(reg.FindStringSubmatch(req.GetAnother())[1]) |
33 | 18 | } |
34 | 19 | if reg := regexp.MustCompile("(?P<nested_name>.*)"); reg.MatchString(req.GetFieldName().GetNested()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetFieldName().GetNested())[1])) > 0 { |
35 | | - if !seen["nested_name"] { |
36 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "nested_name", url.QueryEscape(reg.FindStringSubmatch(req.GetFieldName().GetNested())[1]))) |
37 | | - seen["nested_name"] = true |
38 | | - } |
| 20 | + routingHeadersMap["nested_name"] = url.QueryEscape(reg.FindStringSubmatch(req.GetFieldName().GetNested())[1]) |
39 | 21 | } |
40 | 22 | if reg := regexp.MustCompile("(?P<part_of_nested>projects/[^/]+)/bars"); reg.MatchString(req.GetFieldName().GetNested()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetFieldName().GetNested())[1])) > 0 { |
41 | | - if !seen["part_of_nested"] { |
42 | | - routingHeaders = append(routingHeaders, fmt.Sprintf("%s=%s", "part_of_nested", url.QueryEscape(reg.FindStringSubmatch(req.GetFieldName().GetNested())[1]))) |
43 | | - seen["part_of_nested"] = true |
44 | | - } |
| 23 | + routingHeadersMap["part_of_nested"] = url.QueryEscape(reg.FindStringSubmatch(req.GetFieldName().GetNested())[1]) |
45 | 24 | } |
46 | | - hds := []string{"x-goog-request-params", strings.Join(routingHeaders, "&")} |
| 25 | + for headerName, headerValue := range routingHeadersMap { |
| 26 | + routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue) |
| 27 | + } |
| 28 | + routingHeaders = strings.TrimSuffix(routingHeaders, "&") |
| 29 | + hds := []string{"x-goog-request-params", routingHeaders} |
47 | 30 |
|
48 | 31 | hds = append(c.xGoogHeaders, hds...) |
49 | 32 | ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
|
0 commit comments