fixed registration of root path
This commit is contained in:
parent
f98eb16240
commit
9a1490784e
2 changed files with 3 additions and 3 deletions
|
@ -104,7 +104,7 @@ func (router *Router) validateRoute(path string) error {
|
|||
}
|
||||
|
||||
// path must not end with a slash
|
||||
if path[len(path)-1] == '/' {
|
||||
if len(path) > 1 && path[len(path)-1] == '/' {
|
||||
return fmt.Errorf("URL path must not end with a slash (/)")
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ func TestRouterServerHandler(t *testing.T) {
|
|||
testHandler := TestHandler{CloseChannel: make(chan bool, 2)}
|
||||
|
||||
router := New()
|
||||
router.Handle(http.MethodGet, "/home", testHandler)
|
||||
router.Handle(http.MethodGet, "/", testHandler)
|
||||
listener, err := net.Listen("tcp", "localhost:8081")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
@ -90,7 +90,7 @@ func TestRouterServerHandler(t *testing.T) {
|
|||
go http.Serve(listener, router)
|
||||
|
||||
// call method
|
||||
_, err = http.Get("http://localhost:8081/home")
|
||||
_, err = http.Get("http://localhost:8081/")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue