// addRoute adds the new method and route to a route Tree for debugging and
// informational purposes.
188269
func (res *Resource) addRoute(method string, route string) {
	res.Routes = append(res.Routes, fmt.Sprintf("%s - /%s%s", method, res.Type, route))
}
1004665
func AddRouter(configuration *config.HTTPConfiguration, routerName string, router *config.Router) bool {
	if _, ok := configuration.Routers[routerName]; !ok {
		configuration.Routers[routerName] = router
		return true
	}

	return reflect.DeepEqual(configuration.Routers[routerName], router)
}
90242
func NewRoute(moduleSource *Module, method, path, action, fixedArgs, routesPath string, line int) (r *Route) {
	// Handle fixed arguments
	argsReader := strings.NewReader(string(namespaceReplace([]byte(fixedArgs), moduleSource)))
	csvReader := csv.NewReader(argsReader)
	csvReader.TrimLeadingSpace = true
	fargs, err := csvReader.Read()
	if err != nil && err != io.EOF {
		routerLog.Error("NewRoute: Invalid fixed parameters for string ", "error", err, "fixedargs", fixedArgs)
	}

	r = &Route{
		ModuleSource: moduleSource,
		Method:       strings.ToUpper(method),
		Path:         path,
		Action:       string(namespaceReplace([]byte(action), moduleSource)),
		FixedParams:  fargs,
		TreePath:     treePath(strings.ToUpper(method), path),
		routesPath:   routesPath,
		line:         line,
	}

	// URL pattern
	if !strings.HasPrefix(r.Path, "/") {
		routerLog.Error("NewRoute: Absolute URL required.")
		return
	}

	// Ignore the not found status code
	if action != httpStatusCode {
		routerLog.Debugf("NewRoute: New splitActionPath path:%s action:%s", path, action)
		pathData, found := splitActionPath(&ActionPathData{ModuleSource: moduleSource, Route: r}, r.Action, false)
		if found {
			if pathData.TypeOfController != nil {
				// Assign controller type to avoid looking it up based on name
				r.TypeOfController = pathData.TypeOfController
				// Create the fixed parameters
				if l := len(pathData.Route.FixedParams); l > 0 && len(pathData.FixedParamsByName) == 0 {
					methodType := pathData.TypeOfController.Method(pathData.MethodName)
					if methodType != nil {
						pathData.FixedParamsByName = make(map[string]string, l)
						for i, argValue := range pathData.Route.FixedParams {
							Unbind(pathData.FixedParamsByName, methodType.Args[i].Name, argValue)
						}
					} else {
						routerLog.Panicf("NewRoute: Method %s not found for controller %s", pathData.MethodName, pathData.ControllerName)
					}
				}
			}
			r.ControllerNamespace = pathData.ControllerNamespace
			r.ControllerName = pathData.ControllerName
			r.ModuleSource = pathData.ModuleSource
			r.MethodName = pathData.MethodName

			// The same action path could be used for multiple routes (like the Static.Serve)
		} else {
			routerLog.Panicf("NewRoute: Failed to find controller for route path action %s \n%#v\n", path+"?"+r.Action, actionPathCacheMap)
		}
	}
	return
}
1328031
func (s *DescribeRouteOutput) SetRoute(v *RouteData) *DescribeRouteOutput {
	s.Route = v
	return s
}
277251
func (r *Router) Add(meth, pat string, h http.Handler) *mux.Route {
	return r.NewRoute().PathPrefix(pat).Handler(h).Methods(meth)
}
163444
func (r *RouteGroup) To(methods, path string, handlers ...Handler) *Route {
	route := newRoute(path, r)
	for _, method := range strings.Split(methods, ",") {
		route.add(method, handlers)
	}
	return route
}
577750
func (r *Routes) CreateRoute(ctx context.Context, clusterName string, nameHint string, route *cloudprovider.Route) error {
	klog.V(4).Infof("CreateRoute(%v, %v, %v)", clusterName, nameHint, route)

	onFailure := newCaller()

	ip, _, _ := net.ParseCIDR(route.DestinationCIDR)
	isCIDRv6 := ip.To4() == nil
	addr, err := getAddressByName(r.compute, route.TargetNode, isCIDRv6)

	if err != nil {
		return err
	}

	klog.V(4).Infof("Using nexthop %v for node %v", addr, route.TargetNode)

	router, err := routers.Get(r.network, r.opts.RouterID).Extract()
	if err != nil {
		return err
	}

	routes := router.Routes

	for _, item := range routes {
		if item.DestinationCIDR == route.DestinationCIDR && item.NextHop == addr {
			klog.V(4).Infof("Skipping existing route: %v", route)
			return nil
		}
	}

	routes = append(routes, routers.Route{
		DestinationCIDR: route.DestinationCIDR,
		NextHop:         addr,
	})

	unwind, err := updateRoutes(r.network, router, routes)
	if err != nil {
		return err
	}
	defer onFailure.call(unwind)

	// get the port of addr on target node.
	portID, err := getPortIDByIP(r.compute, route.TargetNode, addr)
	if err != nil {
		return err
	}
	port, err := getPortByID(r.network, portID)
	if err != nil {
		return err
	}

	found := false
	for _, item := range port.AllowedAddressPairs {
		if item.IPAddress == route.DestinationCIDR {
			klog.V(4).Info("Found existing allowed-address-pair: ", item)
			found = true
			break
		}
	}

	if !found {
		newPairs := append(port.AllowedAddressPairs, neutronports.AddressPair{
			IPAddress: route.DestinationCIDR,
		})
		unwind, err := updateAllowedAddressPairs(r.network, port, newPairs)
		if err != nil {
			return err
		}
		defer onFailure.call(unwind)
	}

	klog.V(4).Infof("Route created: %v", route)
	onFailure.disarm()
	return nil
}
689557
func (service *Service) AddRoutes(router *mux.Router) {
	service.router = router
	router.HandleFunc("/v1/oauth/authorize", service.AuthorizeHandler).Methods("GET")
	router.HandleFunc("/v1/oauth/authorize",
		func(w http.ResponseWriter, r *http.Request) {
			w.Header().Add("Allow", "GET")
		}).Methods("OPTIONS")

	router.HandleFunc("/v1/oauth/access_token", service.AccessTokenHandler).Methods("POST")
	router.HandleFunc("/v1/oauth/access_token",
		func(w http.ResponseWriter, r *http.Request) {
			w.Header().Add("Allow", "POST")
			// Allow cors
			w.Header().Add("Access-Control-Allow-Origin", "*")
			w.Header().Add("Access-Control-Allow-Methods", "POST")
			// Allow all requested headers, we do not use them anyway
			w.Header().Add("Access-Control-Allow-Headers", r.Header.Get("Access-Control-Request-Headers"))
		}).Methods("OPTIONS")

	router.HandleFunc("/v1/oauth/jwt", service.JWTHandler).Methods("POST", "GET")
	router.HandleFunc("/v1/oauth/jwt",
		func(w http.ResponseWriter, r *http.Request) {
			w.Header().Add("Allow", "GET,POST")
		}).Methods("OPTIONS")
	router.HandleFunc("/v1/oauth/jwt/refresh", service.RefreshJWTHandler).Methods("POST", "GET")
	router.HandleFunc("/v1/oauth/jwt/refresh",
		func(w http.ResponseWriter, r *http.Request) {
			w.Header().Add("Allow", "GET,POST")
		}).Methods("OPTIONS")

	InitModels()
}
904808
func (r *Router) AddRoute(rule string, priority int, handler http.Handler) error {
	parse, err := r.parser.Parse(rule)
	if err != nil {
		return fmt.Errorf("error while parsing rule %s: %v", rule, err)
	}

	buildTree, ok := parse.(treeBuilder)
	if !ok {
		return fmt.Errorf("error while parsing rule %s", rule)
	}

	if priority == 0 {
		priority = len(rule)
	}

	route := r.NewRoute().Handler(handler).Priority(priority)
	return addRuleOnRoute(route, buildTree())
}
421213
func wrapRoute(middlewares *alice.Chain) func(*mux.Route, *mux.Router, []*mux.Route) error {
	return func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
		handler, err := middlewares.Then(route.GetHandler())
		if err != nil {
			return err
		}

		route.Handler(handler)
		return nil
	}
}
153418
func NewRoute(server, service, method string) *Route {
	return &Route{server, service, method}
}
51206
func (s *UpdateRouteOutput) SetRoute(v *RouteData) *UpdateRouteOutput {
	s.Route = v
	return s
}
1268391
func newRoute(path string, handler Handler) *route {
	route := &route{
		handler: handler,
	}
	strs := strings.Split(path, "/")
	strs = removeEmptyStrings(strs)
	pattern := `^`
	for _, str := range strs {
		if str[0] == '{' && str[len(str)-1] == '}' {
			pattern += `/`
			pattern += `([^/]*)`
			route.paramNames = append(route.paramNames, str[1:(len(str)-1)])
		} else {
			pattern += `/`
			pattern += str
		}
	}
	pattern += `/?$`
	route.regex = regexp.MustCompile(pattern)
	return route
}
899155
func (s *Server) addRouter(r router.Router) {
	s.routers = append(s.routers, r)
}
394454
func (api *MobileGatewayAPI) AddSIMRoute(id int64, simID int64, prefix string) (bool, error) {

	routes, err := api.GetSIMRoutes(id)
	if err != nil {
		return false, err
	}

	param := &sacloud.MobileGatewaySIMRoutes{
		SIMRoutes: routes,
	}
	index, added := param.AddSIMRoute(simID, prefix)
	if index < 0 || added == nil {
		return false, nil
	}

	return api.SetSIMRoutes(id, param)
}
610615
func (c *Client) UpdateRoute(appID string, routeID string, route *router.Route) error {
	return c.Put(fmt.Sprintf("/apps/%s/routes/%s", appID, routeID), route, route)
}
900661
func (g *Cloud) CreateRoute(ctx context.Context, clusterName string, nameHint string, route *cloudprovider.Route) error {
	ctx, cancel := cloud.ContextWithCallTimeout()
	defer cancel()

	mc := newRoutesMetricContext("create")

	targetInstance, err := g.getInstanceByName(mapNodeNameToInstanceName(route.TargetNode))
	if err != nil {
		return mc.Observe(err)
	}
	cr := &compute.Route{
		Name:            truncateClusterName(clusterName) + "-" + nameHint,
		DestRange:       route.DestinationCIDR,
		NextHopInstance: fmt.Sprintf("zones/%s/instances/%s", targetInstance.Zone, targetInstance.Name),
		Network:         g.NetworkURL(),
		Priority:        1000,
		Description:     k8sNodeRouteTag,
	}
	err = g.c.Routes().Insert(ctx, meta.GlobalKey(cr.Name), cr)
	if isHTTPErrorCode(err, http.StatusConflict) {
		klog.Infof("Route %q already exists.", cr.Name)
		err = nil
	}
	return mc.Observe(err)
}