// NewRouter intialises a new instance and returns the pointer.
333024
func NewRouter() *Router {
	// Tries to run hub, if already running nothing will happen.
	hub.run()
	// Returns pointer to instance.
	return &Router{
		callbacks:                make(map[string]func(*Connection, interface{})),
		extensions:               make(map[reflect.Type]reflect.Value),
		closeFunc:                func(*Connection) {}, // Empty placeholder close function.
		connectionFunc:           func(*Connection, *http.Request) {},
		handshakeFunc:            func(http.ResponseWriter, *http.Request) bool { return true }, // Handshake always allowed.
		protocol:                 initialProtocol,
		useHeartbeats:            true,
		connExtensionConstructor: defaultConnectionExtension,
		Origins:                  make([]string, 0),
	}
}
788133
func NewRouter(server *SyncServer) *mux.Router {

	// API framework routes
	router := mux.NewRouter().StrictSlash(true)

	// Application
	router.HandleFunc("/v1-ssync/getChecksum", server.getChecksum).Methods("GET")
	router.HandleFunc("/v1-ssync/open", server.open).Methods("GET")
	router.HandleFunc("/v1-ssync/close", server.close).Methods("POST")
	router.HandleFunc("/v1-ssync/sendHole", server.sendHole).Methods("POST")
	router.HandleFunc("/v1-ssync/writeData", server.writeData).Methods("POST")

	return router
}
707519
func newRoute() *Route {
	return &Route{
		handlers:   make(map[string]http.Handler),
		middleware: make([]*middlewareForVerb, 0),
		children:   make([]*Route, 0),
	}
}
495053
func NewWithHTTP(http *http.Client) Client {
	c := newRouterClient()
	http.Transport = c.HTTP.Transport
	c.HTTP = http
	return c
}
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
}
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)
}
27036
func newRouter() (*router, chan bool) {
	router := &router{routes: list.New(), messages: make(chan *packets.PublishPacket), stop: make(chan bool)}
	stop := router.stop
	return router, stop
}
904382
func NewRouter() *httprouter.Router {
	router := httprouter.New()
	router.NotFound = http.HandlerFunc(notFoundHandler)
	router.MethodNotAllowed = http.HandlerFunc(methodNotAllowedHandler)
	router.PanicHandler = panicHandler
	return router
}
463813
func (s *Server) WithRouter(router *mux.Router) *Server {
	s.router = router
	return s
}
526090
func NewRouter(b Backend, d experimentalProvider, features *map[string]bool) router.Router {
	r := &buildRouter{
		backend:  b,
		daemon:   d,
		features: features,
	}
	r.initRoutes()
	return r
}
1357973
func NewRouter(rootLogger *logrus.Logger, cfg config.Config, bridgeMap map[string]bridge.Factory) (*Router, error) {
	logger := rootLogger.WithFields(logrus.Fields{"prefix": "router"})

	r := &Router{
		Config:           cfg,
		BridgeMap:        bridgeMap,
		Message:          make(chan config.Message),
		MattermostPlugin: make(chan config.Message),
		Gateways:         make(map[string]*Gateway),
		logger:           logger,
	}
	sgw := samechannel.New(cfg)
	gwconfigs := append(sgw.GetConfig(), cfg.BridgeValues().Gateway...)

	for idx := range gwconfigs {
		entry := &gwconfigs[idx]
		if !entry.Enable {
			continue
		}
		if entry.Name == "" {
			return nil, fmt.Errorf("%s", "Gateway without name found")
		}
		if _, ok := r.Gateways[entry.Name]; ok {
			return nil, fmt.Errorf("Gateway with name %s already exists", entry.Name)
		}
		r.Gateways[entry.Name] = New(rootLogger, entry, r)
	}
	return r, nil
}
205254
func (rg *RouteGroup) newRoute(method, path string) *Route {
	return &Route{
		group:    rg,
		method:   method,
		path:     path,
		template: buildURLTemplate(rg.prefix + path),
	}
}
347130
func NewRouter(routes Routes, handlers Handlers) (http.Handler, error) {
	p := pat.New()

	for _, route := range routes {
		handler, ok := handlers[route.Name]
		if !ok {
			return nil, fmt.Errorf("missing handler %s", route.Name)
		}

		switch method := strings.ToUpper(route.Method); method {
		case GET, HEAD, POST, PUT, PATCH, DELETE, CONNECT, OPTIONS, TRACE:
			p.Add(method, route.Path, handler)
		default:
			return nil, fmt.Errorf("invalid verb: %s", route.Method)
		}
	}

	return p, nil
}
1043130
func NewHTTPRouter(prefix string, notAllowedHandler http.Handler) Routeable {
	router := httprouter.New()
	router.HandleMethodNotAllowed = true
	router.MethodNotAllowed = notAllowedHandler
	return &HTTPRouter{router: router}
}
276925
func NewURLBuilder(root *url.URL, relative bool) *URLBuilder {
	return &URLBuilder{
		root:     root,
		router:   Router(),
		relative: relative,
	}
}
364995
func newRouter(p *producerImpl) *mux.Router {

	router := mux.NewRouter().StrictSlash(true)
	if p.config.DCOSRole == "agent" {
		loadRoutes(agentRoutes, router, p)
	}

	loadRoutes(routes, router, p)

	return router
}
12285
func New() *Router {
	return &Router{
		dynamicRoutes: dynamicSet{},
		routes:        &Trie{},
		Logger:        logger,
		Verbose:       true,
	}
}