fixed registration of root path

This commit is contained in:
Martin Riedl 2019-08-07 23:11:20 +02:00
parent f98eb16240
commit 9a1490784e
Signed by: martinr92
GPG key ID: FB68DA65516A804C
2 changed files with 3 additions and 3 deletions

View file

@ -104,7 +104,7 @@ func (router *Router) validateRoute(path string) error {
} }
// path must not end with a slash // 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 (/)") return fmt.Errorf("URL path must not end with a slash (/)")
} }

View file

@ -82,7 +82,7 @@ func TestRouterServerHandler(t *testing.T) {
testHandler := TestHandler{CloseChannel: make(chan bool, 2)} testHandler := TestHandler{CloseChannel: make(chan bool, 2)}
router := New() router := New()
router.Handle(http.MethodGet, "/home", testHandler) router.Handle(http.MethodGet, "/", testHandler)
listener, err := net.Listen("tcp", "localhost:8081") listener, err := net.Listen("tcp", "localhost:8081")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -90,7 +90,7 @@ func TestRouterServerHandler(t *testing.T) {
go http.Serve(listener, router) go http.Serve(listener, router)
// call method // call method
_, err = http.Get("http://localhost:8081/home") _, err = http.Get("http://localhost:8081/")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }