Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding Router.Name to create new Route #457

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ func (r *Router) NewRoute() *Route {
return route
}

// Name registers a new route with a name.
// See Route.Name().
func (r *Router) Name(name string) *Route {
return r.NewRoute().Name(name)
}

// Handle registers a new route with a matcher for the URL path.
// See Route.Path() and Route.Handler().
func (r *Router) Handle(path string, handler http.Handler) *Route {
Expand Down
7 changes: 4 additions & 3 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,10 +1441,11 @@ func TestNamedRoutes(t *testing.T) {
r3.NewRoute().Name("g")
r3.NewRoute().Name("h")
r3.NewRoute().Name("i")
r3.Name("j")

if r1.namedRoutes == nil || len(r1.namedRoutes) != 9 {
t.Errorf("Expected 9 named routes, got %v", r1.namedRoutes)
} else if r1.Get("i") == nil {
if r1.namedRoutes == nil || len(r1.namedRoutes) != 10 {
t.Errorf("Expected 10 named routes, got %v", r1.namedRoutes)
} else if r1.Get("j") == nil {
t.Errorf("Subroute name not registered")
}
}
Expand Down