added path replacement rule

This commit is contained in:
ssttevee 2017-04-25 11:13:39 -07:00
parent 5a8215a1e4
commit aa8375e82b
5 changed files with 82 additions and 0 deletions

View file

@ -75,6 +75,13 @@ func (r *Rules) pathStrip(paths ...string) *mux.Route {
return r.route.route
}
func (r *Rules) replacePath(paths ...string) *mux.Route {
for _, path := range paths {
r.route.replacePath = path
}
return r.route.route
}
func (r *Rules) addPrefix(paths ...string) *mux.Route {
for _, path := range paths {
r.route.addPrefix = path
@ -116,6 +123,7 @@ func (r *Rules) parseRules(expression string, onRule func(functionName string, f
"Headers": r.headers,
"HeadersRegexp": r.headersRegexp,
"AddPrefix": r.addPrefix,
"ReplacePath": r.replacePath,
}
if len(expression) == 0 {

View file

@ -65,6 +65,7 @@ type serverRoute struct {
route *mux.Route
stripPrefixes []string
addPrefix string
replacePath string
}
// NewServer returns an initialized Server.
@ -806,6 +807,14 @@ func (server *Server) wireFrontendBackend(serverRoute *serverRoute, handler http
}
}
// path replace
if len(serverRoute.replacePath) > 0 {
handler = &middlewares.ReplacePath{
Path: serverRoute.replacePath,
Handler: handler,
}
}
serverRoute.route.Handler(handler)
}