Fix regex with PathStrip
This commit is contained in:
parent
74925ba996
commit
bf3673879f
5 changed files with 156 additions and 17 deletions
|
@ -75,6 +75,16 @@ func (r *Rules) pathStrip(paths ...string) *mux.Route {
|
|||
return r.route.route
|
||||
}
|
||||
|
||||
func (r *Rules) pathStripRegex(paths ...string) *mux.Route {
|
||||
sort.Sort(bySize(paths))
|
||||
r.route.stripPrefixesRegex = paths
|
||||
router := r.route.route.Subrouter()
|
||||
for _, path := range paths {
|
||||
router.Path(strings.TrimSpace(path))
|
||||
}
|
||||
return r.route.route
|
||||
}
|
||||
|
||||
func (r *Rules) replacePath(paths ...string) *mux.Route {
|
||||
for _, path := range paths {
|
||||
r.route.replacePath = path
|
||||
|
@ -99,6 +109,16 @@ func (r *Rules) pathPrefixStrip(paths ...string) *mux.Route {
|
|||
return r.route.route
|
||||
}
|
||||
|
||||
func (r *Rules) pathPrefixStripRegex(paths ...string) *mux.Route {
|
||||
sort.Sort(bySize(paths))
|
||||
r.route.stripPrefixesRegex = paths
|
||||
router := r.route.route.Subrouter()
|
||||
for _, path := range paths {
|
||||
router.PathPrefix(strings.TrimSpace(path))
|
||||
}
|
||||
return r.route.route
|
||||
}
|
||||
|
||||
func (r *Rules) methods(methods ...string) *mux.Route {
|
||||
return r.route.route.Methods(methods...)
|
||||
}
|
||||
|
@ -113,17 +133,19 @@ func (r *Rules) headersRegexp(headers ...string) *mux.Route {
|
|||
|
||||
func (r *Rules) parseRules(expression string, onRule func(functionName string, function interface{}, arguments []string) error) error {
|
||||
functions := map[string]interface{}{
|
||||
"Host": r.host,
|
||||
"HostRegexp": r.hostRegexp,
|
||||
"Path": r.path,
|
||||
"PathStrip": r.pathStrip,
|
||||
"PathPrefix": r.pathPrefix,
|
||||
"PathPrefixStrip": r.pathPrefixStrip,
|
||||
"Method": r.methods,
|
||||
"Headers": r.headers,
|
||||
"HeadersRegexp": r.headersRegexp,
|
||||
"AddPrefix": r.addPrefix,
|
||||
"ReplacePath": r.replacePath,
|
||||
"Host": r.host,
|
||||
"HostRegexp": r.hostRegexp,
|
||||
"Path": r.path,
|
||||
"PathStrip": r.pathStrip,
|
||||
"PathStripRegex": r.pathStripRegex,
|
||||
"PathPrefix": r.pathPrefix,
|
||||
"PathPrefixStrip": r.pathPrefixStrip,
|
||||
"PathPrefixStripRegex": r.pathPrefixStripRegex,
|
||||
"Method": r.methods,
|
||||
"Headers": r.headers,
|
||||
"HeadersRegexp": r.headersRegexp,
|
||||
"AddPrefix": r.addPrefix,
|
||||
"ReplacePath": r.replacePath,
|
||||
}
|
||||
|
||||
if len(expression) == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue