// Routing associates a routing value to the alias.
// This basically sets index and search routing to the same value.
335030
func (a *AliasAddAction) Routing(routing string) *AliasAddAction {
	a.routing = routing
	return a
}
1333030
func (r *Route) URL(pairs ...string) (*url.URL, error) {
	return r.route.URL(pairs...)
}
318382
func lookup(route *netlink.Route) *netlink.Route {
	var filter uint64
	if route.Dst != nil {
		filter |= netlink.RT_FILTER_DST
	}
	if route.Table != 0 {
		filter |= netlink.RT_FILTER_TABLE
	}
	if route.Scope != 0 {
		filter |= netlink.RT_FILTER_SCOPE
	}
	if route.Gw != nil {
		filter |= netlink.RT_FILTER_GW
	}
	if route.LinkIndex != 0 {
		filter |= netlink.RT_FILTER_OIF
	}

	routes, err := netlink.RouteListFiltered(ipFamily(route.Dst.IP), route, filter)
	if err != nil {
		return nil
	}

	for _, r := range routes {
		if r.Dst != nil && route.Dst == nil {
			continue
		}

		if route.Dst != nil && r.Dst == nil {
			continue
		}

		if route.Table != 0 && route.Table != r.Table {
			continue
		}

		aMaskLen, aMaskBits := r.Dst.Mask.Size()
		bMaskLen, bMaskBits := route.Dst.Mask.Size()
		if r.Scope == route.Scope &&
			aMaskLen == bMaskLen && aMaskBits == bMaskBits &&
			r.Dst.IP.Equal(route.Dst.IP) && r.Gw.Equal(route.Gw) {
			return &r
		}
	}

	return nil
}
621899
func (r *router) Match(url, method string) (*Route, Params) {
	cn, ok := r.trees[method]
	if !ok {
		return nil, nil
	}
	var params = make(Params, 0, strings.Count(url, "/"))
	for _, n := range cn.edges {
		e, newParams := r.matchNode(n, url, params)
		if e != nil {
			return e.handle, newParams
		}
	}
	return nil, nil
}
378457
func (r *Router) Lookup(method string, path string) (httprouter.Handle, httprouter.Params, bool) {
	return r.Router.Lookup(method, path)
}
1243890
func (r *Route) Name(name string) *Route {
	r.route.Name(name)
	return r
}
322690
func (g *Group) Route(methods interface{}, url string, c interface{}, middlewares ...Handler) {
	g.routers = append(g.routers, groupRouter{methods, url, c, middlewares})
}
1036528
func (s *MultiTermvectorItem) Routing(routing string) *MultiTermvectorItem {
	s.routing = routing
	return s
}
786663
func (r *BulkIndexRequest) Routing(routing string) *BulkIndexRequest {
	r.routing = routing
	r.source = nil
	return r
}
1254066
func (s *GetService) Routing(routing string) *GetService {
	s.routing = routing
	return s
}
1324223
func (item *MultiGetItem) Routing(routing string) *MultiGetItem {
	item.routing = routing
	return item
}
518408
func (a *AliasAddAction) Index(index ...string) *AliasAddAction {
	a.index = append(a.index, index...)
	return a
}
1328725
func (r *Router) Redirect(w http.ResponseWriter, req *http.Request, path string, code int) {
	http.Redirect(w, req, r.prefix+path, code)
}
1321457
func (r *router) Route(ms interface{}, url string, c interface{}, handlers ...Handler) {
	vc := reflect.ValueOf(c)
	if vc.Kind() == reflect.Func {
		switch ms.(type) {
		case string:
			s := strings.Split(ms.(string), ":")
			r.addFunc([]string{s[0]}, url, c, handlers)
		case []string:
			var newSlice []string
			for _, m := range ms.([]string) {
				s := strings.Split(m, ":")
				newSlice = append(newSlice, s[0])
			}
			r.addFunc(newSlice, url, c, handlers)
		default:
			panic("unknow methods format")
		}
	} else if vc.Kind() == reflect.Ptr && vc.Elem().Kind() == reflect.Struct {
		if handler, ok := vc.Interface().(http.Handler); ok {
			r.Route(ms, url, handler.ServeHTTP, handlers...)
			return
		}
		var methods = make(map[string]string)
		switch ms.(type) {
		case string:
			s := strings.Split(ms.(string), ":")
			if len(s) == 1 {
				methods[s[0]] = strings.Title(strings.ToLower(s[0]))
			} else if len(s) == 2 {
				methods[s[0]] = strings.TrimSpace(s[1])
			} else {
				panic("unknow methods format")
			}
		case []string:
			for _, m := range ms.([]string) {
				s := strings.Split(m, ":")
				if len(s) == 1 {
					methods[s[0]] = strings.Title(strings.ToLower(s[0]))
				} else if len(s) == 2 {
					methods[s[0]] = strings.TrimSpace(s[1])
				} else {
					panic("unknow format")
				}
			}
		case map[string]string:
			methods = ms.(map[string]string)
		default:
			panic("unsupported methods")
		}

		r.addStruct(methods, url, c, handlers)
	} else {
		panic("not support route type")
	}
}
306128
func (s *SearchService) Routing(routings ...string) *SearchService {
	s.routing = strings.Join(routings, ",")
	return s
}
644032
func Lookup(route Route) (*Route, error) {
	link, err := netlink.LinkByName(route.Device)
	if err != nil {
		return nil, fmt.Errorf("unable to find interface '%s' of route: %s", route.Device, err)
	}

	routeSpec := route.getNetlinkRoute()
	routeSpec.LinkIndex = link.Attrs().Index

	nlRoute := lookup(&routeSpec)
	if nlRoute == nil {
		return nil, nil
	}

	result := &Route{
		Local:   nlRoute.Src,
		Device:  link.Attrs().Name,
		MTU:     nlRoute.MTU,
		Scope:   nlRoute.Scope,
		Nexthop: &nlRoute.Gw,
	}

	if nlRoute.Dst != nil {
		result.Prefix = *nlRoute.Dst
	}

	return result, nil
}
401908
func (conf *Config) Alias(server string) string {
	longestMatch := ""
	serverAlias := ""
	for alias, serverConf := range conf.Servers {
		if strings.HasPrefix(server, serverConf.Server) {
			if len(serverConf.Server) > len(longestMatch) {
				longestMatch = serverConf.Server
				serverAlias = alias
			}
		}
	}
	return serverAlias
}