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