in src/go/configgenerator/routegen/helpers/backend_route.go [55:111]
func (r *BackendRouteGenerator) GenRoutesForMethod(methodCfg *MethodCfg, filterGens []filtergen.FilterGenerator) ([]*routepb.Route, error) {
methodName, err := util.SelectorToMethodName(methodCfg.OperationName)
if err != nil {
return nil, fmt.Errorf("fail to parse method short name from selector %q: %v", methodCfg.OperationName, err)
}
routeMatchers, err := MakePerMethodRouteMatchers(methodCfg.HTTPPattern, r.DisallowColonInWildcardPathSegment)
if err != nil {
return nil, fmt.Errorf("fail to make backend per-method route matchers for operation %q: %v", methodCfg.OperationName, err)
}
var routes []*routepb.Route
for i, routeMatcher := range routeMatchers {
routeAction := &routepb.RouteAction{
ClusterSpecifier: &routepb.RouteAction_Cluster{
Cluster: methodCfg.BackendClusterName,
},
}
if methodCfg.HostRewrite != "" {
routeAction.HostRewriteSpecifier = &routepb.RouteAction_HostRewriteLiteral{
HostRewriteLiteral: methodCfg.HostRewrite,
}
}
MaybeAddDeadlines(r.DeadlineCfg, routeAction, methodCfg.Deadline, methodCfg.IsStreaming)
if err := MaybeAddRetryPolicy(r.RetryCfg, routeAction); err != nil {
return nil, err
}
perFilterConfig, err := makePerRouteFilterConfig(methodCfg.OperationName, methodCfg.HTTPPattern, filterGens)
if err != nil {
return nil, fmt.Errorf("fail to make per-route filter config for route matcher %d: %v", i, err)
}
route := &routepb.Route{
Name: methodCfg.OperationName,
Match: routeMatcher.RouteMatch,
Action: &routepb.Route_Route{
Route: routeAction,
},
Decorator: &routepb.Decorator{
// TODO(taoxuy@): check if the generated span name length less than the limit.
// Note we don't add ApiName to reduce the length of the span name.
Operation: fmt.Sprintf("%s %s", util.SpanNamePrefix, methodName),
},
TypedPerFilterConfig: perFilterConfig,
}
MaybeAddHSTSHeader(r.HSTSCfg, route)
MaybeAddOperationNameHeader(r.OperationNameCfg, route, methodCfg.OperationName)
routes = append(routes, route)
}
return routes, nil
}