Exemplo n.º 1
0
// clondedRoute returns a clone of the named route from the router. Routes
// must be cloned to avoid modifying them during url generation.
func (ub *URLBuilder) cloneRoute(name string) *mux.Route {
	route := new(mux.Route)
	*route = *ub.router.GetRoute(name) // clone the route

	return route.
		Schemes(ub.root.Scheme).
		Host(ub.root.Host)
}
Exemplo n.º 2
0
func (m Match) SetRoute(r *mux.Route) *mux.Route {
	if m.Prefix != "" {
		r = r.PathPrefix(m.Prefix)
	}
	if m.Hosts != nil && len(m.Hosts) > 0 {
		for _, host := range m.Hosts {
			r = r.Host(host)
		}
	}
	if m.Methods != nil && len(m.Methods) > 0 {
		r = r.Methods(m.Methods...)
	}
	if m.Schemes != nil && len(m.Schemes) > 0 {
		for _, scheme := range m.Schemes {
			r = r.Schemes(scheme)
		}
	}
	if m.Queries != nil && len(m.Queries) > 0 {
		for _, m := range m.Queries {
			for k, v := range m {
				r = r.Queries(k, v)
			}
		}
	}
	if m.Headers != nil && len(m.Headers) > 0 {
		for _, m := range m.Headers {
			for k, v := range m {
				r = r.Headers(k, v)
			}
		}
	}
	if m.Custom != nil && len(m.Custom) > 0 {
		// lookup custom function by name
		// func(r *http.Request, rm *RouteMatch) bool
	}
	return r
}