🔨 fix mount tree build

Co-Authored-By: RW <7063188+ReneWerner87@users.noreply.github.com>
pull/830/head
Fenny 2020-09-26 13:46:14 +02:00
parent 753391b217
commit 3b5997a3df
2 changed files with 16 additions and 17 deletions

View File

@ -257,19 +257,20 @@ func Test_App_Nested_Params(t *testing.T) {
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
}
// func Test_App_Use_App(t *testing.T) {
// micro := New()
// micro.Get("/doe", func(c *Ctx) error {
// return c.SendStatus(StatusOK)
// })
// go test -run Test_App_Mount
func Test_App_Mount(t *testing.T) {
micro := New()
micro.Get("/doe", func(c *Ctx) error {
return c.SendStatus(StatusOK)
})
// app := New()
// app.Use("/john", micro)
app := New()
app.Mount("/john", micro)
// resp, err := app.Test(httptest.NewRequest("GET", "/john/doe", nil))
// utils.AssertEqual(t, nil, err, "app.Test(req)")
// utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
// }
resp, err := app.Test(httptest.NewRequest("GET", "/john/doe", nil))
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
}
func Test_App_Use_Params(t *testing.T) {
app := New()

View File

@ -16,8 +16,6 @@ import (
// Router defines all router handle interface includes app and group router.
type Router interface {
Mount(prefix string, fiber *App) Router
Use(args ...interface{}) Router
Get(path string, handlers ...Handler) Router
@ -35,6 +33,8 @@ type Router interface {
All(path string, handlers ...Handler) Router
Group(prefix string, handlers ...Handler) Router
Mount(prefix string, fiber *App) Router
}
// Route is a struct that holds all metadata for each registered handler
@ -275,8 +275,6 @@ func (app *App) register(method, pathRaw string, handlers ...Handler) Router {
// Add route to stack
app.addRoute(method, &route)
}
// Build router tree
app.buildTree()
return app
}
@ -385,8 +383,6 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router {
app.addRoute(MethodGet, &route)
// Add HEAD route
app.addRoute(MethodHead, &route)
// Build router tree
app.buildTree()
return app
}
@ -409,6 +405,8 @@ func (app *App) addRoute(method string, route *Route) {
// Add route to the stack
app.stack[m] = append(app.stack[m], route)
}
// Build router tree
app.buildTree()
}
// buildTree build the prefix tree from the previously registered routes