Skip to content

Commit

Permalink
adding Router.Name to create new Route
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousben committed Feb 27, 2019
1 parent 8559a4f commit e2c55f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit e2c55f8

Please sign in to comment.