Add tests for GetPathTemplate. Added GetHostTemplate and associated tests as well
This commit is contained in:
17
route.go
17
route.go
@@ -532,10 +532,11 @@ func (r *Route) URLPath(pairs ...string) (*url.URL, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// URLPathTemplate returns the template used to match against for the route
|
||||
//
|
||||
// GetPathTemplate and GetHostTemplate returns the template used to match against for the route
|
||||
// This is userful for building simple REST API documentation,
|
||||
// and instrumentation for services like New Relic to ensure consistent reporting
|
||||
// The route must have a path defined.
|
||||
func (r *Route) URLPathTemplate() (string, error) {
|
||||
func (r *Route) GetPathTemplate() (string, error) {
|
||||
if r.err != nil {
|
||||
return "", r.err
|
||||
}
|
||||
@@ -545,6 +546,16 @@ func (r *Route) URLPathTemplate() (string, error) {
|
||||
return r.regexp.path.template, nil
|
||||
}
|
||||
|
||||
func (r *Route) GetHostTemplate() (string, error) {
|
||||
if r.err != nil {
|
||||
return "", r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.host == nil {
|
||||
return "", errors.New("mux: route doesn't have a host")
|
||||
}
|
||||
return r.regexp.host.template, nil
|
||||
}
|
||||
|
||||
// prepareVars converts the route variable pairs into a map. If the route has a
|
||||
// BuildVarsFunc, it is invoked.
|
||||
func (r *Route) prepareVars(pairs ...string) (map[string]string, error) {
|
||||
|
||||
Reference in New Issue
Block a user