func()

in src/go/configinfo/service_info.go [569:611]


func (s *ServiceInfo) addBackendRuleToMethod(r *confpb.BackendRule, addressToCluster map[string]string, method *MethodInfo, isHTTPBackend bool) error {
	scheme, hostname, port, path, err := util.ParseURI(r.Address)
	if err != nil {
		return fmt.Errorf("error parsing remote backend rule's address for operation (%v), %v", r.Selector, err)
	}
	address := fmt.Sprintf("%v:%v", hostname, port)

	if _, exist := addressToCluster[address]; !exist {
		// Create a cluster for the remote backend.
		protocol, tls, err := util.ParseBackendProtocol(scheme, r.Protocol)
		if err != nil {
			return fmt.Errorf("error parsing remote backend rule's protocol for operation (%v), %v", r.Selector, err)
		}
		if protocol == util.GRPC {
			if isHTTPBackend {
				return fmt.Errorf("gRPC protocol conflicted with http backend; this is an API compiler bug")
			}
			s.GrpcSupportRequired = true
		}

		backendClusterName := fmt.Sprintf("backend-cluster-%s", address)
		s.RemoteBackendClusters = append(s.RemoteBackendClusters,
			&BackendRoutingCluster{
				ClusterName: backendClusterName,
				UseTLS:      tls,
				Protocol:    protocol,
				Hostname:    hostname,
				Port:        port,
			})
		addressToCluster[address] = backendClusterName
	}

	backendClusterName := addressToCluster[address]

	if bi, err := s.ruleToBackendInfo(r, scheme, hostname, path, backendClusterName, port); err != nil {
		return fmt.Errorf("error processing remote backend rule for operation (%v), %v", r.Selector, err)
	} else if isHTTPBackend {
		method.HttpBackendInfo = bi
	} else {
		method.BackendInfo = bi
	}
	return nil
}