Added method Route.GetPathRegexp

This commit is contained in:
Bulat Gaifullin
2017-04-18 09:50:17 +03:00
committed by Kamil Kisiel
parent 4c1c3952b7
commit 1856953e53
2 changed files with 35 additions and 0 deletions

View File

@@ -558,6 +558,20 @@ func (r *Route) GetPathTemplate() (string, error) {
return r.regexp.path.template, nil
}
// GetPathRegexp returns the expanded regular expression used to match route path.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not define a path.
func (r *Route) GetPathRegexp() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp == nil || r.regexp.path == nil {
return "", errors.New("mux: route does not have a path")
}
return r.regexp.path.regexp.String(), nil
}
// GetHostTemplate returns the template used to build the
// route match.
// This is useful for building simple REST API documentation and for instrumentation