diff --git a/core/router/api_builder.go b/core/router/api_builder.go index b5aee7a7..35b64425 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -142,7 +142,9 @@ func (repo *repository) getAll() []*Route { func (repo *repository) register(route *Route) { for i, r := range repo.routes { - if route.Equal(r) { + // 14 August 2019 allow register same path pattern with different macro functions, + // see #1058 + if route.DeepEqual(r) { // replace existing with the latest one. repo.routes = append(repo.routes[:i], repo.routes[i+1:]...) continue diff --git a/core/router/path.go b/core/router/path.go index 8df69db8..25a49e85 100644 --- a/core/router/path.go +++ b/core/router/path.go @@ -234,10 +234,10 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri slashIdx := strings.IndexByte(s, '/') if slashIdx == 0 { // no subdomain - return "", cleanPath(s) + return "", s // cleanPath(s) } - return s[0:slashIdx], cleanPath(s[slashIdx:]) // return subdomain without slash, path with slash + return s[0:slashIdx], s[slashIdx:] // cleanPath(s[slashIdx:]) // return subdomain without slash, path with slash } // RoutePathReverserOption option signature for the RoutePathReverser. diff --git a/core/router/route.go b/core/router/route.go index 9746e423..60446246 100644 --- a/core/router/route.go +++ b/core/router/route.go @@ -80,6 +80,7 @@ func NewRoute(method, subdomain, unparsedPath, mainHandlerName string, MainHandlerName: mainHandlerName, FormattedPath: formattedPath, } + return route, nil } @@ -157,13 +158,20 @@ func (r Route) String() string { r.Method, r.Subdomain, r.Tmpl().Src) } -// Equal compares the method, subdomaind and the +// Equal compares the method, subdomain and the // underline representation of the route's path, // instead of the `String` function which returns the front representation. func (r *Route) Equal(other *Route) bool { return r.Method == other.Method && r.Subdomain == other.Subdomain && r.Path == other.Path } +// DeepEqual compares the method, subdomain, the +// underline representation of the route's path, +// and the template source. +func (r *Route) DeepEqual(other *Route) bool { + return r.Equal(other) && r.tmpl.Src == other.tmpl.Src +} + // Tmpl returns the path template, // it contains the parsed template // for the route's path.