示例#1
0
文件: mux.go 项目: gorward/mux
// HANDLER create route using GorwardRouter values
func (r GowardRouter) Handler(handler http.Handler) Router {
	var route *mux.Route

	if r.FMiddleware != nil {
		handler = bindMiddlewares(handler, r.FMiddleware...)
	}

	if r.FPath == "/" && r.FParentRouter != nil {
		route = r.FParentRouter.NewRoute()
		route = route.Path(r.FPrefix)
	} else {
		route = r.FRouter.NewRoute()
		route.Path(r.FPath)
	}
	if r.FHost != "" {
		route = route.Host(r.FHost)
	}
	if r.Methods != nil {
		route = route.Methods(r.FMethods...)
	}

	route.Handler(handler)

	return r
}
示例#2
0
func (app *App) RegisterRoute(route *mux.Route, dispatch dispatchFunc, nameRequired nameRequiredFunc, accessRecords customAccessRecordsFunc) {
	// TODO(stevvooe): This odd dispatcher/route registration is by-product of
	// some limitations in the gorilla/mux router. We are using it to keep
	// routing consistent between the client and server, but we may want to
	// replace it with manual routing and structure-based dispatch for better
	// control over the request execution.
	route.Handler(app.dispatcher(dispatch, nameRequired, accessRecords))
}
示例#3
0
文件: server.go 项目: tayzlor/traefik
func (server *Server) wireFrontendBackend(routes map[string]types.Route, newRoute *mux.Route, handler http.Handler) {
	// strip prefix
	var strip bool
	for _, route := range routes {
		switch route.Rule {
		case "PathStrip":
			newRoute.Handler(&middlewares.StripPrefix{
				Prefix:  route.Value,
				Handler: handler,
			})
			strip = true
			break
		case "PathPrefixStrip":
			newRoute.Handler(&middlewares.StripPrefix{
				Prefix:  route.Value,
				Handler: handler,
			})
			strip = true
			break
		}
	}
	if !strip {
		newRoute.Handler(handler)
	}
}